scipy.ndimage.grey_dilation

scipy.ndimage.grey_dilation(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0)[源代码]

使用结构元素或与平面结构元素对应的示意图计算灰度膨胀。

灰度膨胀是一种数学形态学运算。对于完整扁平的结构元素的简单情况,可以将其视为滑动窗口上的最大过滤。

参数
inputarray_like

要在其上计算灰度膨胀的数组。

size整数元组

用于灰度扩展的扁平且完整的结构元素的形状。在以下情况下可选 footprintstructure 是提供的。

footprint整型数组,可选

用于灰度膨胀的平面结构元素的非无限元素的位置。非零值给出了选择最大值的中心的邻居集。

structure整型数组,可选

用于灰度膨胀的结构元素。 structure 可以是非平坦的结构元素。

output数组,可选

可以提供用于存储扩张的输出的阵列。

mode{‘反射’,‘常量’,‘最近’,‘镜像’,‘换行’},可选

这个 mode 参数确定如何处理数组边框, cval 模式等于‘Constant’时的值。默认值为‘Reflect’

cval标量,可选

在以下情况下填充输入的过去边缘的值 mode 是“恒定的”。默认值为0.0。

origin标量,可选

这个 origin 参数控制过滤的位置。默认%0

退货
grey_dilationndarray

的灰度膨胀 input

注意事项

由在域E上定义的结构元素s输入的图像的灰度膨胀由下式给出:

(输入+s)(X)=max{输入(Y)+s(x-y),对于E中的y}

具体地,对于对于E中的y定义为s(Y)=0的结构元素,灰度膨胀计算由E定义的滑动窗口内的输入图像的最大值。

灰度膨胀 [1] 是一种 数学形态学 运营 [2].

参考文献

1

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

2

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

示例

>>> from scipy import ndimage
>>> a = np.zeros((7,7), dtype=int)
>>> a[2:5, 2:5] = 1
>>> a[4,4] = 2; a[2,3] = 3
>>> a
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 3, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 2, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> ndimage.grey_dilation(a, size=(3,3))
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 1, 3, 3, 3, 1, 0],
       [0, 1, 3, 3, 3, 1, 0],
       [0, 1, 3, 3, 3, 2, 0],
       [0, 1, 1, 2, 2, 2, 0],
       [0, 1, 1, 2, 2, 2, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> ndimage.grey_dilation(a, footprint=np.ones((3,3)))
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 1, 3, 3, 3, 1, 0],
       [0, 1, 3, 3, 3, 1, 0],
       [0, 1, 3, 3, 3, 2, 0],
       [0, 1, 1, 2, 2, 2, 0],
       [0, 1, 1, 2, 2, 2, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> s = ndimage.generate_binary_structure(2,1)
>>> s
array([[False,  True, False],
       [ True,  True,  True],
       [False,  True, False]], dtype=bool)
>>> ndimage.grey_dilation(a, footprint=s)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 3, 1, 0, 0],
       [0, 1, 3, 3, 3, 1, 0],
       [0, 1, 1, 3, 2, 1, 0],
       [0, 1, 1, 2, 2, 2, 0],
       [0, 0, 1, 1, 2, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]])
>>> ndimage.grey_dilation(a, size=(3,3), structure=np.ones((3,3)))
array([[1, 1, 1, 1, 1, 1, 1],
       [1, 2, 4, 4, 4, 2, 1],
       [1, 2, 4, 4, 4, 2, 1],
       [1, 2, 4, 4, 4, 3, 1],
       [1, 2, 2, 3, 3, 3, 1],
       [1, 2, 2, 3, 3, 3, 1],
       [1, 1, 1, 1, 1, 1, 1]])