scipy.ndimage.

spline_filter#

scipy.ndimage.spline_filter(input, order=3, output=<class 'numpy.float64'>, mode='mirror')[原始碼]#

多維 spline 濾波器。

參數:
inputarray_like

輸入陣列。

orderint, optional

spline 的階數,預設值為 3。

outputndarray 或 dtype,optional

要放入輸出的陣列,或是返回陣列的 dtype。預設值為 numpy.float64

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

mode 參數決定輸入陣列如何在其邊界之外延伸。預設值為 ‘mirror’。每個有效值的行為如下 (請參閱 邊界模式 以取得更多圖表和詳細資訊)

‘reflect’ (d c b a | a b c d | d c b a)

輸入透過反射最後一個像素的邊緣來延伸。此模式有時也稱為半樣本對稱。

‘grid-mirror’

這是 ‘reflect’ 的同義詞。

‘constant’ (k k k k | a b c d | k k k k)

輸入透過以相同的常數值填充邊緣以外的所有值來延伸,此常數值由 cval 參數定義。在輸入的邊緣之外不執行內插。

‘grid-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)

輸入透過反射最後一個像素的中心來延伸。此模式有時也稱為全樣本對稱。

‘grid-wrap’ (a b c d | a b c d | a b c d)

輸入透過環繞到對邊緣來延伸。

‘wrap’ (d b c d | a b c d | b c a b)

輸入透過環繞到對邊緣來延伸,但方式是最後一點和初始點完全重疊。在這種情況下,在重疊點將選擇哪個樣本沒有明確定義。

返回:
spline_filterndarray

已過濾的陣列。具有與 input 相同的形狀。

另請參閱

spline_filter1d

沿著給定軸計算 1-D spline 濾波器。

註解

多維濾波器實作為 1-D spline 濾波器的序列。中間陣列以與輸出相同的資料類型儲存。因此,對於精度有限的輸出類型,結果可能不精確,因為中間結果可能以不足的精度儲存。

對於複數值 input,此函數獨立處理實部和虛部。

在版本 1.6.0 中新增: 新增複數值支援。

範例

我們可以使用多維 spline 過濾影像

>>> from scipy.ndimage import spline_filter
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> orig_img = np.eye(20)  # create an image
>>> orig_img[10, :] = 1.0
>>> sp_filter = spline_filter(orig_img, order=3)
>>> f, ax = plt.subplots(1, 2, sharex=True)
>>> for ind, data in enumerate([[orig_img, "original image"],
...                             [sp_filter, "spline filter"]]):
...     ax[ind].imshow(data[0], cmap='gray_r')
...     ax[ind].set_title(data[1])
>>> plt.tight_layout()
>>> plt.show()
../../_images/scipy-ndimage-spline_filter-1.png