scipy.ndimage.

grey_closing#

scipy.ndimage.grey_closing(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0, *, axes=None)[源]#

多维灰度闭运算。

灰度闭运算是由灰度膨胀和灰度腐蚀的连续操作组成的。

参数:
inputarray_like

要计算灰度闭运算的数组。

sizetuple of ints

用于灰度闭运算的扁平完整结构元素的形状。如果提供了 footprintstructure,则此参数可选。

footprintarray of ints, 可选

用于灰度闭运算的扁平结构元素的非无限元素的位置。

structurearray of ints, 可选

用于灰度闭运算的结构元素。structure 可以是非扁平的结构元素。structure 数组会将偏移量应用于邻域中的像素(在膨胀期间偏移量为加性,在腐蚀期间为减性)。

outputarray, 可选

可以提供一个用于存储闭运算结果的数组。

mode{‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}, 可选

mode 参数决定数组边界的处理方式,其中 cval 是当 mode 等于 'constant' 时的值。默认值为 'reflect'

cvalscalar, 可选

如果 mode 为 'constant',用于填充输入边界以外的值。默认值为 0.0。

originscalar, 可选

origin 参数控制滤波器的放置。默认值为 0

axestuple of int 或 None

应用过滤器的轴。如果为 None,则 input 将沿所有轴进行过滤。如果提供了 origin 元组,其长度必须与轴的数量匹配。

返回:
grey_closingndarray

使用 structureinput 进行灰度闭运算的结果。

注意

使用扁平结构元素进行灰度闭运算的作用是平滑深层局部最小值,而二值闭运算则填充小孔。

参考文献

示例

>>> from scipy import ndimage
>>> import numpy as np
>>> a = np.arange(36).reshape((6,6))
>>> a[3,3] = 0
>>> a
array([[ 0,  1,  2,  3,  4,  5],
       [ 6,  7,  8,  9, 10, 11],
       [12, 13, 14, 15, 16, 17],
       [18, 19, 20,  0, 22, 23],
       [24, 25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34, 35]])
>>> ndimage.grey_closing(a, size=(3,3))
array([[ 7,  7,  8,  9, 10, 11],
       [ 7,  7,  8,  9, 10, 11],
       [13, 13, 14, 15, 16, 17],
       [19, 19, 20, 20, 22, 23],
       [25, 25, 26, 27, 28, 29],
       [31, 31, 32, 33, 34, 35]])
>>> # Note that the local minimum a[3,3] has disappeared