scipy.ndimage.
white_tophat#
- scipy.ndimage.white_tophat(input, size=None, footprint=None, structure=None, output=None, mode='reflect', cval=0.0, origin=0, *, axes=None)[source]#
多維白色高帽濾波器。
- 參數:
- inputarray_like
輸入。
- sizetuple of ints
用於濾波器的平面且完整結構元素的形狀。如果提供 footprint 或 structure 則為選用項目。
- 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 元組,則其長度必須符合軸的數量。
- 返回:
- outputndarray
input 與 structure 濾波器的結果。
參見
範例
從亮峰中減去灰色背景。
>>> from scipy.ndimage import generate_binary_structure, white_tophat >>> import numpy as np >>> square = generate_binary_structure(rank=2, connectivity=3) >>> bright_on_gray = np.array([[2, 3, 3, 3, 2], ... [3, 4, 5, 4, 3], ... [3, 5, 9, 5, 3], ... [3, 4, 5, 4, 3], ... [2, 3, 3, 3, 2]]) >>> white_tophat(input=bright_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]])