Two versions of the flood-fill algorithm have been implemented in Python here:
http://arcgisandpython.blogspot.de/2012/01/python-flood-fill-algorithm.html
The first, simpler one contained two undefined variables, but here is a
working version:
import numpy as npimport scipy as spimport scipy.ndimagedef flood_fill(test_array,h_max=255): input_array = np.copy(test_array) el = sp.ndimage.generate_binary_structure(2,2).astype(np.int) inside_mask = sp.ndimage.binary_erosion(~np.isnan(input_array), structure=el) output_array = np.copy(input_array) output_array[inside_mask]=h_max output_old_array = np.copy(input_array) output_old_array.fill(0) el = sp.ndimage.generate_binary_structure(2,1).astype(np.int) while not np.array_equal(output_old_array, output_array): output_old_array = np.copy(output_array) output_array = np.maximum(input_array,sp.ndimage.grey_erosion(output_array, size=(3,3), footprint=el)) return output_array
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)