當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python SciPy ndimage.extrema用法及代碼示例

本文簡要介紹 python 語言中 scipy.ndimage.extrema 的用法。

用法:

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

計算標簽處數組值的最小值和最大值,以及它們的位置。

參數

input ndarray

N-D 要處理的圖像數據。

labels ndarray,可選

輸入中的特征標簽。如果不是無,則必須與輸入的形狀相同。

index int 或整數序列,可選

要包含在輸出中的標簽。如果 None (默認),使用非零標簽的所有值。

返回

minimums, maximums int 或 ndarray

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

min_positions, max_positions 元組或元組列表

每個元組給出對應的最小值或最大值的N-D 坐標。

例子

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

可以使用標簽和索引指定要處理的特征:

>>> 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)])

如果沒有給出索引,則處理非零標簽:

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

相關用法


注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.ndimage.extrema。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。