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]#
多維灰度開運算。
灰度開運算包含灰度腐蝕和灰度膨脹的連續操作。
- 參數:
- inputarray_like
計算灰度開運算的陣列。
- sizetuple of ints
用於灰度開運算的平面且完整結構元素的形狀。如果提供了 footprint 或 structure,則為選填。
- footprint整數陣列,選填
用於灰度開運算的平面結構元素中非無限元素的位置。
- structure整數陣列,選填
用於灰度開運算的結構元素。structure 可以是非平面結構元素。structure 陣列將偏移量應用於鄰域中的像素(偏移量在膨脹期間是加法的,在腐蝕期間是減法的)。
- output陣列,選填
可以提供用於儲存開運算輸出的陣列。
- mode{‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}, 選填
mode 參數決定如何處理陣列邊界,其中 cval 是當 mode 等於 ‘constant’ 時的值。預設值為 ‘reflect’
- cval純量,選填
如果 mode 為 ‘constant’,則用於填充輸入邊緣外的值。預設值為 0.0。
- origin純量,選填
origin 參數控制濾波器的位置。預設值為 0
- axestuple of int 或 None
套用濾波器的軸。如果為 None,則沿所有軸過濾 input。如果提供了 origin 元組,則其長度必須與軸的數量相符。
- 回傳:
- grey_openingndarray
input 經過 structure 灰度開運算的結果。
註解
使用平面結構元素的灰度開運算的作用是平滑局部最大值,而二元開運算則會擦除小物體。
參考文獻
範例
>>> 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