scipy.ndimage.
gaussian_filter1d#
- scipy.ndimage.gaussian_filter1d(input, sigma, axis=-1, order=0, output=None, mode='reflect', cval=0.0, truncate=4.0, *, radius=None)[source]#
一維高斯濾波器。
- 參數:
- inputarray_like
輸入陣列。
- sigmascalar
高斯核的標準差
- axisint, optional
計算時沿著 input 的軸。預設值為 -1。
- orderint, optional
階數 0 對應於與高斯核的卷積。正階數對應於與高斯導數的卷積。
- outputarray 或 dtype, optional
放置輸出的陣列,或傳回陣列的 dtype。預設情況下,將建立與輸入相同 dtype 的陣列。
- mode{‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}, optional
mode 參數決定輸入陣列如何在其邊界之外延伸。預設值為 ‘reflect’。每個有效值的行為如下
- ‘reflect’ (d c b a | a b c d | d c b a)
輸入透過反射最後一個像素的邊緣來延伸。此模式有時也稱為半樣本對稱。
- ‘constant’ (k k k k | a b c d | k k k k)
輸入透過用相同的常數值填充邊緣之外的所有值來延伸,常數值由 cval 參數定義。
- ‘nearest’ (a a a a | a b c d | d d d d)
輸入透過複製最後一個像素來延伸。
- ‘mirror’ (d c b | a b c d | c b a)
輸入透過反射最後一個像素的中心來延伸。此模式有時也稱為全樣本對稱。
- ‘wrap’ (a b c d | a b c d | a b c d)
輸入透過環繞到相對的邊緣來延伸。
為了與內插函數保持一致,也可以使用以下模式名稱
- ‘grid-mirror’
這是 ‘reflect’ 的同義詞。
- ‘grid-constant’
這是 ‘constant’ 的同義詞。
- ‘grid-wrap’
這是 ‘wrap’ 的同義詞。
- cvalscalar, optional
如果 mode 為 ‘constant’,則填充輸入邊緣之外的值。預設值為 0.0。
- truncatefloat, optional
在此標準差數量處截斷濾波器。預設值為 4.0。
- radiusNone 或 int, optional
高斯核的半徑。如果指定,則核心的大小將為
2*radius + 1
,並且 truncate 會被忽略。預設值為 None。
- 回傳:
- gaussian_filter1dndarray
註解
高斯核沿每個軸的大小將為
2*radius + 1
。如果 radius 為 None,則將使用預設值radius = round(truncate * sigma)
。範例
>>> from scipy.ndimage import gaussian_filter1d >>> import numpy as np >>> gaussian_filter1d([1.0, 2.0, 3.0, 4.0, 5.0], 1) array([ 1.42704095, 2.06782203, 3. , 3.93217797, 4.57295905]) >>> gaussian_filter1d([1.0, 2.0, 3.0, 4.0, 5.0], 4) array([ 2.91948343, 2.95023502, 3. , 3.04976498, 3.08051657]) >>> import matplotlib.pyplot as plt >>> rng = np.random.default_rng() >>> x = rng.standard_normal(101).cumsum() >>> y3 = gaussian_filter1d(x, 3) >>> y6 = gaussian_filter1d(x, 6) >>> plt.plot(x, 'k', label='original data') >>> plt.plot(y3, '--', label='filtered, sigma=3') >>> plt.plot(y6, ':', label='filtered, sigma=6') >>> plt.legend() >>> plt.grid() >>> plt.show()