scipy.ndimage.binary_erosion

scipy.ndimage.binary_erosion(input, structure=None, iterations=1, mask=None, output=None, border_value=0, origin=0, brute_force=False)[源代码]

具有给定结构元素的多维二元侵蚀。

二值侵蚀是一种用于图像处理的数学形态学运算。

参数
inputarray_like

要侵蚀的二进制图像。非零(True)元素构成要侵蚀的子集。

structureARRAY_LIKE,可选

用于侵蚀的结构元素。非零元素被认为是True。如果没有提供结构化元素,则生成方形连通性等于1的元素。

iterations整型,可选

侵蚀会反复发生 iterations 次数(默认情况下为一次)。如果迭代次数小于1,则会重复侵蚀,直到结果不再更改。

maskARRAY_LIKE,可选

如果给定了掩码,则在每次迭代中只修改在相应掩码元素处具有True值的那些元素。

outputndarray,可选

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

border_valueint(强制转换为0或1),可选

输出数组中边框处的值。

origin整型或整型元组,可选

过滤的位置,默认为0。

brute_force布尔值,可选

内存条件:如果为False,则仅跟踪其值在上一次迭代中更改的像素作为在当前迭代中更新(侵蚀)的候选像素;如果为True,则将所有像素视为侵蚀候选,而不考虑上一次迭代中发生的情况。默认情况下为False。

退货
binary_erosion一群野猪

结构元素对输入的侵蚀。

注意事项

侵蚀 [1] 是一种数学形态学运算 [2] 它使用结构元素来缩小图像中的形状。结构元素对图像的二进制侵蚀是以该点为中心的结构元素的叠加完全包含在图像的非零元素集中的点的轨迹。

参考文献

1

https://en.wikipedia.org/wiki/Erosion_%28morphology%29

2

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

示例

>>> from scipy import ndimage
>>> a = np.zeros((7,7), dtype=int)
>>> a[1:6, 2:5] = 1
>>> a
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> ndimage.binary_erosion(a).astype(a.dtype)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> #Erosion removes objects smaller than the structure
>>> ndimage.binary_erosion(a, structure=np.ones((5,5))).astype(a.dtype)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])