Tracking brightest Pixels

Hey all, I was wondering if anyone has any experience tracking brightness of pixels from the video grabber? I see that there is a getBrightness in ofImage. I’m trying to draw an ellipse on the brightest point in the video.

1 Like

This can be done in a number of ways. The simplest brute-force method would be to look at each pixel, keeping track of the x / y position of the brightest one that you find. With an 8-bit image, the problem comes when there are more than one pixel with a maximum brightness of say – 255. Which pixel position do you choose?

A second option is a “threshold” approach. Basically you apply a threshold to a image – say a grayscale image – and use the ofxOpenCv contour finder to find the positions of the “blobs” that represent the brightest pixels (after a thresholding operation). If you get multiple blobs back, you can choose the one that is the biggest based on the number of pixels in the blob or the size of the bounding box.

In order to have stable results actually relating to the image content and not be disturbed by noise, you might want to low-pass filter the image, e.g. with a gaussian filter mask of some lets say 3-7 pixels width (ymmv). OpenCV can certainly do this, no time to look into the specifics right now, just a hint.

Afterwards, as @bakercp writes, I would just do a one-pass over the image searching for the intensity maximum (sum of R, G, B values) if it’s only a single maximum you want, otherwise thresholding as mentioned.


1 Like

@Maurice, once you have the image form the video grabber, you could iterate pixel by pixel, and for each of them:

 ofColor c = image.getColor(x, y);
 float intensity = c.getLightness(); 

Have a look at this tutorial, it uses a treshold too.