Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GPUImage: How to determine average pixel value for given rectangle in processed image

I am using GPUImage to process incoming video and I would like to then consider a given square subregion of the image and determine the average pixel value of the pixels in that region. Can anyone advise me on how to accomplish this? Even information on how to acquire pixel data for a pixel at coordinate(x,y) in the image would be useful.

Apologies if this is a simple question, but I am new to computer vision and the way to do this was not clear to me from the available documentation. Thank you.

like image 512
KeithComito Avatar asked May 31 '13 17:05

KeithComito


1 Answers

First, use a GPUImageCropFilter to extract the rectangular region of your original image. This uses normalized coordinates (0.0 - 1.0), so you'll have to translate from the pixel location and size to these normalized coordinates.

Next, feed the output from the crop filter into a GPUImageAverageColor operation. This will average the pixel color within that region and use the colorAverageProcessingFinishedBlock that you set as a callback. The block will return to you the average red, green, blue, and alpha channel values for the pixels in that region.

For an example of both of these operations in action, see the FilterShowcase example that comes with the framework.

like image 58
Brad Larson Avatar answered Nov 09 '22 07:11

Brad Larson