def generate_binary_structure(rank, connectivity):
 if (connectivity < 1):
  connectivity = 1
 if (rank < 1):
  if (connectivity < 1):
   return numpy.array(0, dtype=bool)
  else:
   return numpy.array(1, dtype=bool)
 output = numpy.fabs((numpy.indices(([3] * rank)) - 1))
 output = numpy.add.reduce(output, 0)
 return numpy.asarray((output <= connectivity), dtype=bool)

def generate_binary_structure ( rank , connectivity ) : if ( connectivity < 1 ) : connectivity = 1 if ( rank < 1 ) : if ( connectivity < 1 ) : return numpy . array ( 0 , dtype = bool ) else : return numpy . array ( 1 , dtype = bool ) output = numpy . fabs ( ( numpy . indices ( ( [ 3 ] * rank ) ) - 1 ) ) output = numpy . add . reduce ( output , 0 ) return numpy . asarray ( ( output <= connectivity ) , dtype = bool )
generate a binary structure for binary morphological operations .