Image entropy calculation

I ran into some unpleasant problem with my recorder. Some people still use it with analog tuners, and analog tuners tend to spit out “snow” if there is no signal.

The problem is that when noise enters the encoder, it becomes completely crazy and first consumes the entire processor, and then freezes. Since the main question is that the recorder should remain on and work no matter what I need, I have to figure out how to do this, so the encoder will not be exposed to data that it cannot process.

So, the idea is to create an “entropy detector” - a simple and small subroutine that will go through the frame buffer data and calculate the entropy index, that is, how the data in the picture is actually random.

The result of this procedure will be a number equal to 0 for a complete inverse image, and 1 for a completely random image - snow, that is.

The procedure itself should only be for forward scanning, with several local variables that fit well into the registers.

I could use zlib or 7z api for such a task, but I really would like to cook something myself.

Any ideas?

+1
c ++ video entropy
Dec 05 '10 at 10:01
source share
1 answer

PNG works this way (approximately): for each pixel, replace its value with the value that it has minus the pixel value. Do it from right to left.

Then you can calculate the entropy (bits per character) by creating a table of how often this value appears now, making relative values ​​from these absolute values ​​and adding the results log2 (n) * n for each element.

Oh, and you have to do this for each color channel (r, g, b) separately.

For the result, take the average number of bits per character for the channels and divide it by 2 ^ 8 (assuming you have 8 bits per color).

+2
Dec 05 '10 at
source share



All Articles