scipy.ndimage.
black_tophat#
- scipy.ndimage.black_tophat(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0, *, axes=None)[源]#
多维黑帽滤波。
- 参数:
- inputarray_like
输入。
- sizeint 元组, 可选
用于滤波的平坦且完整的结构元素的形状。如果提供了 footprint 或 structure,则此项为可选。
- footprintint 数组, 可选
用于黑帽滤波的平坦结构元素的非无限元素位置。
- structureint 数组, 可选
用于滤波的结构元素。structure 可以是非平坦的结构元素。structure 数组对邻域中的像素应用偏移量(在膨胀期间为加法偏移,在腐蚀期间为减法偏移)
- output数组, 可选
可以提供一个用于存储滤波输出的数组。
- mode{'reflect', 'constant', 'nearest', 'mirror', 'wrap'}, 可选
mode 参数决定了数组边界的处理方式,其中当 mode 等于 'constant' 时,cval 是填充值。默认为 'reflect'
- cval标量, 可选
如果 mode 为 'constant',用于填充输入边缘外的值。默认为 0.0。
- origin标量, 可选
origin 参数控制滤波器的放置。默认 0
- axesint 元组或 None
应用滤波的轴。如果为 None,则 input 沿所有轴进行滤波。如果提供了 origin 元组,则其长度必须与轴的数量匹配。
- 返回:
- black_tophatndarray
input 与 structure 滤波后的结果。
另请参阅
示例
将暗峰变为亮峰并减去背景。
>>> from scipy.ndimage import generate_binary_structure, black_tophat >>> import numpy as np >>> square = generate_binary_structure(rank=2, connectivity=3) >>> dark_on_gray = np.array([[7, 6, 6, 6, 7], ... [6, 5, 4, 5, 6], ... [6, 4, 0, 4, 6], ... [6, 5, 4, 5, 6], ... [7, 6, 6, 6, 7]]) >>> black_tophat(input=dark_on_gray, structure=square) array([[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 1, 5, 1, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]])