scipy.ndimage.extrema

scipy.ndimage.extrema(input, labels=None, index=None)[源代码]

计算标签处数组的值的最小值和最大值,以及它们的位置。

参数
inputndarray

要处理的N-D图像数据。

labelsndarray,可选

输入中要素的标签。如果不是无,则必须与相同的形状 input

index整型或整型序列,可选

要包括在输出中的标签。如果为None(默认值),则为非零的所有值 labels 都是用过的。

退货
最小值、最大值整数或ndarray

每个要素中的最小值和最大值。

min_positions, max_positions元组或元组列表

每个元组都给出相应最小值或最大值的N-D坐标。

示例

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