-1

I have been trying to get the minimum and maximum data value of some datasets for a particular set of height and width. Suppose I do have a numpy image of (256,256). I want to get the minimum and maximum data value of the following red box:

1

I tried the following steps so far:

After getting the numpy array with openCV, I did:

r,c = img.shape[0:2] #get the row and columns of the image

for i in range (row): #iterate over all the rows and we are considering all the rows
    for j in range (col)[-50:] #trying to consider only the last 50th cols
         .......

I am stuck at this point, like how to get the minimum and maximum data values from the particular red box pixels.

vimuth
  • 5,064
  • 33
  • 79
  • 116

2 Answers2

0

As the images are arrays, if we have the image in np.Array format, we can index the rows and columns and then calculate the maximum and minimum value of the crop.

EDIT: to select the last 50 columns, use the indexer [-50:] on colum index as follows:


import cv2
import numpy as np

image = cv2.cvtColor(cv2.imread("image/path"), cv2.COLOR_BGR2RGB)

crop = image[:, -50:, :]

print(np.max(crop), np.min(crop))

Cuartero
  • 407
  • 1
  • 6
  • Can we select the co-ordinates of the bounding boxes automatically based on the row and column? Suppose, I want to use all the rows but only last 15 columns for the bounding box. My images are not all same in shape, that’s why I just can’t assign particular co-ordinates for all the images. That’s why I wrote the line checked the row and column of each of the data through (r,c) = image.shape[0:2]. So that after getting the number of the columns, I can only work with the last 15. – Jacob Issac Jan 26 '23 at 19:04
0

You can do the following:

bb = img[:,-50:, :] # gets the red bouding box
max_value = bb.max()
min_value = bb.min()
MSS
  • 3,306
  • 1
  • 19
  • 50