scipy.ndimage.binary_closing¶
- scipy.ndimage.binary_closing(input, structure=None, iterations=1, output=None, origin=0, mask=None, border_value=0, brute_force=False)[源代码]¶
与给定结构元素的多维二进制闭合。
这个 结业 结构元素对输入图像的 侵蚀 的 扩张 结构元素对图像的影响。
- 参数
- inputarray_like
要关闭的二进制数组_LIKE。非零(True)元素构成要关闭的子集。
- structureARRAY_LIKE,可选
用于结束的结构元素。非零元素被认为是True。如果没有提供结构元素,则生成方形连通性等于1的元素(即,只有最近的邻居连接到中心,对角连接的元素不被视为邻居)。
- iterations整型,可选
关闭的膨胀步骤,然后每个侵蚀步骤被重复 iterations 次数(默认情况下为一次)。如果迭代次数小于1,则重复每个操作,直到结果不再更改。仅接受整数次迭代。
- outputndarray,可选
与输入形状相同的数组,输出将放置到该数组中。默认情况下,将创建一个新阵列。
- origin整型或整型元组,可选
过滤的位置,默认为0。
- maskARRAY_LIKE,可选
如果给定了掩码,则在每次迭代中只修改在相应掩码元素处具有True值的那些元素。
1.1.0 新版功能.
- border_valueint(强制转换为0或1),可选
输出数组中边框处的值。
1.1.0 新版功能.
- brute_force布尔值,可选
内存条件:如果为False,则仅跟踪其值在上一次迭代中更改的像素作为当前迭代中要更新的候选像素;如果为True,则将所有像素视为更新候选,而不考虑上一次迭代中发生的情况。默认情况下为False。
1.1.0 新版功能.
- 退货
- binary_closing一群野猪
通过结构化元素结束输入。
注意事项
结业 [1] 是一种数学形态学运算 [2] 这包括对具有相同结构元素的输入的连续扩张和侵蚀。因此,闭合填充了比结构元素更小的孔。
Together with opening (
binary_opening
), closing can be used for noise removal.参考文献
示例
>>> from scipy import ndimage >>> a = np.zeros((5,5), dtype=int) >>> a[1:-1, 1:-1] = 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]]) >>> # Closing removes small holes >>> ndimage.binary_closing(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]]) >>> # Closing is the erosion of the dilation of the input >>> ndimage.binary_dilation(a).astype(int) array([[0, 1, 1, 1, 0], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [0, 1, 1, 1, 0]]) >>> ndimage.binary_erosion(ndimage.binary_dilation(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]])
>>> a = np.zeros((7,7), dtype=int) >>> a[1:6, 2:5] = 1; a[1:3,3] = 0 >>> a array([[0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0], [0, 0, 1, 0, 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]]) >>> # In addition to removing holes, closing can also >>> # coarsen boundaries with fine hollows. >>> ndimage.binary_closing(a).astype(int) array([[0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 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_closing(a, structure=np.ones((2,2))).astype(int) 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]])