[英]How to find the minimum and maximum value from an numpy array image in python?
I do have some numpy array images and I want to find the minimum and maximum value of the element from a certain portion of the image by row and column of the array.我确实有一些 numpy 数组图像,我想按数组的行和列从图像的某个部分找到元素的最小值和最大值。 Suppose, I do have a grayscale numpy image of (512,512), from that I want to find the minimum and the maximum data value between the last 20 columns.假设,我确实有 (512,512) 的灰度 numpy 图像,我想从中找到最后 20 列之间的最小和最大数据值。
I have made a red bounded box and I want to find the values from that box.我制作了一个红色边界框,我想从该框中找到值。 I don't want to set the indexes of the row and column manually not all the images are equal in shape.我不想手动设置行和列的索引,并非所有图像的形状都相同。
I have tried the following so far and got stuck here:到目前为止,我已经尝试了以下方法并被困在这里:
(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])
just use the two methods: np.max(img)
np.min(img)
只需使用两种方法: np.max(img)
np.min(img)
np.max --> return the maximum value of your image (in all rows) np.min --> return the minimum value in all rows np.max --> 返回图像的最大值(在所有行中) np.min --> 返回所有行中的最小值
for maximum value:- np.max(img[:,-20:])
对于最大值:- np.max(img[:,-20:])
for minimum value:- np.min(img[:,-20:])
对于最小值:- np.min(img[:,-20:])
This will only take last 20 columns of the image这只会占用图像的最后 20 列
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.