Home > Blockchain >  Filtering values of an array using pixel positions from an image
Filtering values of an array using pixel positions from an image

Time:08-08

I have a image in greyscale. I have the value of each pixel saved to a text document that I pre-processed and loaded as an array, therefore my array has size 110529.

An example of how my array looks like:

import numpy as np
my_array = np.random.randint(low=18., high=36,size=(110592))

Then, I used OpenCV to draw a ROI around the face in my image like this:

x, y, w, h = cv2.selectROI(my_frame)

and the values of x, y, w, h are:

 95 2 184 286

What I want to do is use the pixel indices in the ROI from that image as reference and use those indices to extract to a new array the values that are inside my_array, so I can have a filtered array with 52624 temperature values that corresponds to the ROI in the image

CodePudding user response:

what you wanted is not called "filtering" but a "numpy slice":

x, y, w, h = cv2.selectROI(my_frame)
roi = my_frame[y: h, x:x w]
  • Related