繁体   English   中英

如何从python中的numpy数组图像中找到最小值和最大值?

[英]How to find the minimum and maximum value from an numpy array image in python?

我确实有一些 numpy 数组图像,我想按数组的行和列从图像的某个部分找到元素的最小值和最大值。 假设,我确实有 (512,512) 的灰度 numpy 图像,我想从中找到最后 20 列之间的最小和最大数据值。

我制作了一个红色边界框,我想从该框中找到值。 我不想手动设置行和列的索引,并非所有图像的形状都相同。

图片

到目前为止,我已经尝试了以下方法并被困在这里:

(r, c) = img.shape #returns the row and the column of the image

for x in range(r): #considering all the rows as shown in the image
   for y in range(c)[-20:]: #trying to consider only last 20 columns (incorrect maybe)
      a = np.min(img[i,j])
      b = np.max(img[i,j])

只需使用两种方法: np.max(img) np.min(img)

np.max --> 返回图像的最大值(在所有行中) np.min --> 返回所有行中的最小值

对于最大值:- np.max(img[:,-20:])

对于最小值:- np.min(img[:,-20:])

这只会占用图像的最后 20 列

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM