def _compute_neighbors(image, structure, offset):
 structure[tuple(offset)] = 0
 locations = np.transpose(np.nonzero(structure))
 sqdistances = np.sum(((locations - offset) ** 2), axis=1)
 neighborhood = (np.ravel_multi_index(locations.T, image.shape) - np.ravel_multi_index(offset, image.shape)).astype(np.int32)
 sorted_neighborhood = neighborhood[np.argsort(sqdistances)]
 return sorted_neighborhood

def _compute_neighbors ( image , structure , offset ) : structure [ tuple ( offset ) ] = 0 locations = np . transpose ( np . nonzero ( structure ) ) sqdistances = np . sum ( ( ( locations - offset ) ** 2 ) , axis = 1 ) neighborhood = ( np . ravel_multi_index ( locations . T , image . shape ) - np . ravel_multi_index ( offset , image . shape ) ) . astype ( np . int32 ) sorted_neighborhood = neighborhood [ np . argsort ( sqdistances ) ] return sorted_neighborhood
compute neighborhood as an array of linear offsets into the image .