scipy.ndimage.
grey_opening#
- scipy.ndimage.grey_opening(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0, *, axes=None)[source]#
多维灰度开运算。
灰度开运算是灰度腐蚀和灰度膨胀的连续操作。
- 参数:
- input类数组对象
要计算灰度开运算的数组。
- size整数元组
用于灰度开运算的扁平且完整结构元素的形状。如果提供了 footprint 或 structure,则此项为可选。
- footprint整型数组,可选
用于灰度开运算的扁平结构元素的非无限元素位置。
- structure整型数组,可选
用于灰度开运算的结构元素。structure 可以是非扁平结构元素。structure 数组会对邻域中的像素应用偏移(膨胀时偏移为加性,腐蚀时为减性)。
- output数组,可选
可以提供一个数组用于存储开运算的输出。
- mode{'reflect','constant','nearest','mirror','wrap'},可选
mode 参数决定了数组边界的处理方式,其中当 mode 等于 'constant' 时,cval 是其对应的值。默认值为 'reflect'。
- cval标量,可选
如果 mode 为 'constant',则用于填充输入数组边缘之外的值。默认值为 0.0。
- origin标量,可选
origin 参数控制滤波器的放置。默认值为 0。
- axes整数元组或 None
应用过滤器的轴。如果为 None,则对 input 的所有轴进行过滤。如果提供了 origin 元组,其长度必须与轴的数量匹配。
- 返回值:
- grey_openingndarray
使用 structure 对 input 进行灰度开运算的结果。
注释
使用扁平结构元素进行灰度开运算的作用是平滑高局部最大值,而二值开运算则用于擦除小对象。
参考
示例
>>> from scipy import ndimage >>> import numpy as np >>> a = np.arange(36).reshape((6,6)) >>> a[3, 3] = 50 >>> a array([[ 0, 1, 2, 3, 4, 5], [ 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17], [18, 19, 20, 50, 22, 23], [24, 25, 26, 27, 28, 29], [30, 31, 32, 33, 34, 35]]) >>> ndimage.grey_opening(a, size=(3,3)) array([[ 0, 1, 2, 3, 4, 4], [ 6, 7, 8, 9, 10, 10], [12, 13, 14, 15, 16, 16], [18, 19, 20, 22, 22, 22], [24, 25, 26, 27, 28, 28], [24, 25, 26, 27, 28, 28]]) >>> # Note that the local maximum a[3,3] has disappeared