Home > OS >  How to find the minimum and maximum value from an numpy array image in python?
How to find the minimum and maximum value from an numpy array image in python?

Time:01-27

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. 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. Please check the image where 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.

The picture

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

Kindly help please!

CodePudding user response:

just use the two methods: 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

CodePudding user response:

for maximum value :- np.max(img[:,-20:])

for minimum value :- np.min(img[:,-20:])

This will only take last 20 columns of the image

  • Related