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

輸入。

sizetuple of ints, optional

用於濾波器的平面且完整結構元素的形狀。如果提供 footprintstructure,則為選填。

footprintarray of ints, optional

用於黑帽濾波器的平面結構元素的非無限元素的位置。

structurearray of ints, optional

用於濾波器的結構元素。structure 可以是非平面結構元素。structure 陣列將偏移量應用於鄰域中的像素(偏移量在膨脹期間是加法的,在侵蝕期間是減法的)

outputarray, optional

可用於儲存濾波器輸出的陣列。

mode{‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}, optional

mode 參數決定如何處理陣列邊界,其中 cval 是當 mode 等於 ‘constant’ 時的值。預設值為 ‘reflect’

cvalscalar, optional

如果 mode 為 ‘constant’,則填充輸入邊緣外的值。預設值為 0.0。

originscalar, optional

origin 參數控制濾波器的位置。預設值為 0

axestuple of int or None

要對其應用濾波器的軸。如果為 None,則沿所有軸對 input 進行濾波。如果提供了 origin 元組,則其長度必須與軸的數量相符。

返回:
black_tophatndarray

inputstructure 濾波器的結果。

範例

將暗峰變更為亮峰並減去背景。

>>> 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]])