scipy.ndimage.binary_fill_holes

scipy.ndimage.binary_fill_holes(input, structure=None, output=None, origin=0)[源代码]

填充二进制对象中的空洞。

参数
inputarray_like

具有待填充空洞的N-D二进制阵列

structureARRAY_LIKE,可选

计算中使用的结构元素;大尺寸元素使计算速度更快,但可能会错过由薄区域与背景分隔的孔。默认元素(方形连接性等于1)会产生直观的结果,其中输入中的所有孔都已填充。

outputndarray,可选

与输入形状相同的数组,输出将放置到该数组中。默认情况下,将创建一个新阵列。

originint,整数元组,可选

结构元素的位置。

退货
outndarray

初始图像的变换 input 那里的洞已经被填满了。

注意事项

此函数中使用的算法在于入侵中形状的互补性 input 从图像的外边界,使用二进制膨胀。孔没有连接到边界,因此不会被侵入。结果是入侵区域的互补子集。

参考文献

1

https://en.wikipedia.org/wiki/Mathematical_morphology

示例

>>> from scipy import ndimage
>>> a = np.zeros((5, 5), dtype=int)
>>> a[1:4, 1:4] = 1
>>> a[2,2] = 0
>>> a
array([[0, 0, 0, 0, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 0, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 0, 0, 0, 0]])
>>> ndimage.binary_fill_holes(a).astype(int)
array([[0, 0, 0, 0, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 0, 0, 0, 0]])
>>> # Too big structuring element
>>> ndimage.binary_fill_holes(a, structure=np.ones((5,5))).astype(int)
array([[0, 0, 0, 0, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 0, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 0, 0, 0, 0]])