简体   繁体   English

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

[英]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.

相关问题 如何从numpy数组的一部分列中找到最小值? - How to find the minimum value from a part of a column in numpy array? 如何在 numpy 数组中找到最大负数和最小正数? - How to find maximum negative and minimum positive number in a numpy array? 如何在numpy数组中逐轴查找最小值/最大值 - how to find minimum/maximum values axis by axis in numpy array 如何在Numpy数组中找到局部最大值,然后在其附近追踪局部最小值? - How to find local maximum in a Numpy array and then trace local minimum around it? Python:numpy 和最小化:设置最小和/或最大数组 - Python: numpy and minimize: set the minimum and/or maximum array 如何在不使用 numpy 或在 Python 中展平的情况下在二维数组中找到最小值? - How to find a minimum value in a 2D array without using numpy or flattened in Python? 如何使用 numpy 数组找到具有最小 MSE 的值? - How can I find the value with the minimum MSE with a numpy array? 如何使用 python 从图像的特定高度和宽度计算最小和最大数据值? - How to compute minimum and maximum data value from a certain height and width of an image using python? python 找到子树的最小值和最大值 - python find sub tree minimum and maximum value 如何在 OpenCV Python 中找到图像的最大值 - How to find maximum value of an image in OpenCV Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM