Python equivalent to Matlab funciton 'imfill' for grayscale?

Python equivalent to Matlab funciton 'imfill' for grayscale?,第1张

Python equivalent to Matlab funciton 'imfill' for grayscale?

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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4916434.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存