scipy.ndimage.

percentile_filter#

scipy.ndimage.percentile_filter(input, percentile, size=None, footprint=None, output=None, mode='reflect', cval=0.0, origin=0, *, axes=None)[source]#

計算多維百分位數濾波器。

參數:
inputarray_like

輸入陣列。

percentile純量

百分位數參數可以小於零,例如,percentile = -20 等於 percentile = 80

size純量或 tuple,可選

請參閱下方的 footprint。如果已指定 footprint,則忽略。

footprint陣列,可選

必須定義 sizefootprintsize 給出從輸入陣列中取得的形狀,在每個元素位置,以定義濾波器函數的輸入。footprint 是一個布林陣列,它(隱含地)指定一個形狀,以及此形狀內哪些元素將被傳遞到濾波器函數。因此,size=(n,m) 等效於 footprint=np.ones((n,m))。我們調整 size 以符合輸入陣列的維度數量,因此,如果輸入陣列的形狀為 (10,10,10),且 size 為 2,則實際使用的 size 為 (2,2,2)。當給定 footprint 時,則忽略 size

output陣列或 dtype,可選

放置輸出的陣列,或返回陣列的 dtype。預設情況下,將建立與輸入相同 dtype 的陣列。

mode{‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}, 可選

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’ 的同義詞。

cval純量,可選

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

origin整數或序列,可選

控制濾波器在輸入陣列像素上的放置。值 0(預設值)將濾波器置於像素中心,正值將濾波器向左移動,負值向右移動。通過傳遞與輸入陣列維度數量相等的原點序列,可以沿每個軸指定不同的偏移。

axes整數 tuple 或 None,可選

如果為 None,則沿所有軸過濾 input。否則,沿指定的軸過濾 input。當指定 axes 時,用於 sizeorigin 和/或 mode 的任何 tuple 都必須與 axes 的長度匹配。這些 tuple 中的第 i 個條目對應於 axes 中的第 i 個條目。

返回:
percentile_filterndarray

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

範例

>>> from scipy import ndimage, datasets
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> plt.gray()  # show the filtered result in grayscale
>>> ax1 = fig.add_subplot(121)  # left side
>>> ax2 = fig.add_subplot(122)  # right side
>>> ascent = datasets.ascent()
>>> result = ndimage.percentile_filter(ascent, percentile=20, size=20)
>>> ax1.imshow(ascent)
>>> ax2.imshow(result)
>>> plt.show()
../../_images/scipy-ndimage-percentile_filter-1.png