scipy.ndimage.binary_dilation¶
- scipy.ndimage.binary_dilation(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_dilation一群野猪
结构元素对输入的扩展。
注意事项
扩张 [1] 是一种数学形态学运算 [2] 它使用结构元素来展开图像中的形状。当结构元素的中心位于图像的非零点内时,结构元素对图像的二进制膨胀是结构元素覆盖的点的轨迹。
参考文献
示例
>>> from scipy import ndimage >>> a = np.zeros((5, 5)) >>> a[2, 2] = 1 >>> a array([[ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.], [ 0., 0., 1., 0., 0.], [ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.]]) >>> ndimage.binary_dilation(a) array([[False, False, False, False, False], [False, False, True, False, False], [False, True, True, True, False], [False, False, True, False, False], [False, False, False, False, False]], dtype=bool) >>> ndimage.binary_dilation(a).astype(a.dtype) array([[ 0., 0., 0., 0., 0.], [ 0., 0., 1., 0., 0.], [ 0., 1., 1., 1., 0.], [ 0., 0., 1., 0., 0.], [ 0., 0., 0., 0., 0.]]) >>> # 3x3 structuring element with connectivity 1, used by default >>> struct1 = ndimage.generate_binary_structure(2, 1) >>> struct1 array([[False, True, False], [ True, True, True], [False, True, False]], dtype=bool) >>> # 3x3 structuring element with connectivity 2 >>> struct2 = ndimage.generate_binary_structure(2, 2) >>> struct2 array([[ True, True, True], [ True, True, True], [ True, True, True]], dtype=bool) >>> ndimage.binary_dilation(a, structure=struct1).astype(a.dtype) array([[ 0., 0., 0., 0., 0.], [ 0., 0., 1., 0., 0.], [ 0., 1., 1., 1., 0.], [ 0., 0., 1., 0., 0.], [ 0., 0., 0., 0., 0.]]) >>> ndimage.binary_dilation(a, structure=struct2).astype(a.dtype) 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.]]) >>> ndimage.binary_dilation(a, structure=struct1,\ ... iterations=2).astype(a.dtype) array([[ 0., 0., 1., 0., 0.], [ 0., 1., 1., 1., 0.], [ 1., 1., 1., 1., 1.], [ 0., 1., 1., 1., 0.], [ 0., 0., 1., 0., 0.]])