View Full Version : How to compute mean brightness ?

November 1, 2004, 09:35:12
Dear Sir,

Please help me, how do i compute the mean brightness and subtracting it from each pixel.
I want to stop recording video during light flickering. That is, when then camera focuses directly on a tube light, the camera should not sense it as a valid motion.

please help me with an algorithm to calculate the above. I have to code the logic in Delphi 6.0 but if i get the code in other language, i may try to convert it in delphi and implement the same.

currently my code looks similar to the following:

For y = 0 To ICImagingControl1.ImageHeight - 1 Step 10
For x = 0 To ICImagingControl1.ImageWidth - 1 Step 10
Diff = Diff + Abs(PrevBuf(x, y) - CurBuf(x, y))
Next x
Next y
If Diff > Threshold then HasMoved = True

After this, how do i calculate the mean brightness and subtract it from each pixel.

thanks in advance,
looking forward for a quick reply,

Stefan Geissler
November 1, 2004, 09:59:24
Hello Atul,

To calculate the mean brightness, just calculate the average brightness of each color channel (RGB). Just add all values in you region of interest and then divide them by the count of pixels.
After this you could perform your source code.

A better idea to detect motion in heavily changing lighting conditions would be to detect edges and check, whether the edges have been moved. You use a matrix like the following:
-1, -1,-1,-1,-1,0, 1, 1, 1, 1, 1

Multiply each pixel of a line in your region of interest with this matrix. On positions with high contrast (edges) you will get a higher result value, than in positions with low contrast. You may save these positions and compare them with the next frame. This method is more independent from light than the other method.

I have no sample code for this.

November 1, 2004, 10:12:06
Hi Stefan,
Thanks a million for your reply. I will try the first method you have suggested. But i would not be able to try doing the second method since i am unaware of lots of things in this domain.

The second method you have suggested may definitely be advisable but the fact is i would not be able to do it because i find it to be a complex thing. I will be highly obliged if you could provide me with the source code.

kindly try helping me with the source code for the second method. I dont mind if you take a day or two because its highly important for me to have this functionality done in the next 5-6 days.

thanks & regards,

November 1, 2004, 10:31:19
Dear Stefan,
One doubt i have in computing the mean brightness.

suppose i get the mean brightness in negative nos. like -9.55 or -18.66.
do i have to take the absolute value and subtract it from each pixel or the negative no. should be as it is.

please let me know.

thanks & regards,

Stefan Geissler
November 1, 2004, 15:11:52
Hello Atul,

If you add just the contents of the bytes of the color channels and divide them by the count of pixels, the value can not become negative! Except the data type where to save the result of the addition is too small. Add the byte values to an int or a float type.

Regarding the egde sensing algorithm: I can give you an idea, but please understand me, that i can not write a program for you.