def iterate_structure(structure, iterations, origin=None):
 structure = numpy.asarray(structure)
 if (iterations < 2):
  return structure.copy()
 ni = (iterations - 1)
 shape = [(ii + (ni * (ii - 1))) for ii in structure.shape]
 pos = [(ni * (structure.shape[ii] // 2)) for ii in range(len(shape))]
 slc = [slice(pos[ii], (pos[ii] + structure.shape[ii]), None) for ii in range(len(shape))]
 out = numpy.zeros(shape, bool)
 out[slc] = (structure != 0)
 out = binary_dilation(out, structure, iterations=ni)
 if (origin is None):
  return out
 else:
  origin = _ni_support._normalize_sequence(origin, structure.ndim)
  origin = [(iterations * o) for o in origin]
  return (out, origin)

def iterate_structure ( structure , iterations , origin = None ) : structure = numpy . asarray ( structure ) if ( iterations < 2 ) : return structure . copy ( ) ni = ( iterations - 1 ) shape = [ ( ii + ( ni * ( ii - 1 ) ) ) for ii in structure . shape ] pos = [ ( ni * ( structure . shape [ ii ] // 2 ) ) for ii in range ( len ( shape ) ) ] slc = [ slice ( pos [ ii ] , ( pos [ ii ] + structure . shape [ ii ] ) , None ) for ii in range ( len ( shape ) ) ] out = numpy . zeros ( shape , bool ) out [ slc ] = ( structure != 0 ) out = binary_dilation ( out , structure , iterations = ni ) if ( origin is None ) : return out else : origin = _ni_support . _normalize_sequence ( origin , structure . ndim ) origin = [ ( iterations * o ) for o in origin ] return ( out , origin )
iterate a structure by dilating it with itself .