scipy.ndimage.

extrema#

scipy.ndimage.extrema(input, labels=None, index=None)[source]#

計算標籤陣列中值的最小值和最大值,以及它們的位置。

參數:
inputndarray

要處理的 N 維影像資料。

labelsndarray, optional

輸入中特徵的標籤。如果不是 None,則必須與 input 具有相同的形狀。

indexint 或 int 序列, optional

要包含在輸出中的標籤。如果為 None(預設值),則使用所有非零 labels 的值。

返回:
minimums, maximumsint 或 ndarray

每個特徵中的最小值和最大值。

min_positions, max_positionstuple 或 tuple 列表

每個 tuple 給出相應最小值或最大值的 N 維座標。

範例

>>> import numpy as np
>>> a = np.array([[1, 2, 0, 0],
...               [5, 3, 0, 4],
...               [0, 0, 0, 7],
...               [9, 3, 0, 0]])
>>> from scipy import ndimage
>>> ndimage.extrema(a)
(0, 9, (0, 2), (3, 0))

可以使用 labelsindex 指定要處理的特徵

>>> lbl, nlbl = ndimage.label(a)
>>> ndimage.extrema(a, lbl, index=np.arange(1, nlbl+1))
(array([1, 4, 3]),
 array([5, 7, 9]),
 [(0, 0), (1, 3), (3, 1)],
 [(1, 0), (2, 3), (3, 0)])

如果未給定索引,則處理非零 labels

>>> ndimage.extrema(a, lbl)
(1, 9, (0, 0), (3, 0))