问题描述
我遇到了一些令人讨厌的问题,我的录音机。有些人仍在使用模拟调谐器,如果没有信号,模拟调谐器倾向于吐出雪。
I've run into some nasty problem with my recorder. Some people are still using it with analog tuners, and analog tuners have a tendency to spit out 'snow' if there is no signal present.
问题是当噪声被送入编码器,它完全疯狂,首先消耗所有的CPU,然后最终冻结。因为记录器的主要点是保持和运行,不管什么,我必须弄清楚如何继续这样,所以编码器不会暴露到它不能处理的数据。
The Problem is that when noise is fed into the encoder, it goes completely crazy and first consumes all CPU then ultimately freezes. Since main point od the recorder is to stay up and running no matter what, I have to figure out how to proceed with this, so encoder won't be exposed to the data it can't handle.
因此,想法是创建熵检测器 - 一个简单的小程序,将通过帧缓冲区数据并计算熵指数,即图像中的数据是如何随机的。
So, idea is to create 'entropy detector' - a simple and small routine that will go through the frame buffer data and calculate entropy index i.e. how the data in the picture is actually random.
例程的结果将是一个数字,对于完全后退的图片为0,对于完全随机的图片为雪。
Result from the routine would be a number, that will be 0 for completely back picture, and 1 for completely random picture - snow, that is.
例程本身应该只是向前扫描,只有很少的局部变量可以很好地适合寄存器。
Routine in itself should be forward scanning only, with few local variables that would fit into registers nicely.
我可以使用zlib或7z api
I could use zlib or 7z api for such task, but I would really want to cook something on my own.
任何想法?
推荐答案
PNG工作方式(大约):对于每个像素,将其值替换为它减去剩下的像素值的值。
PNG works this way (approximately): For each pixel, replace its value by the value that it had minus the value of the pixel left to it. Do this from right to left.
然后,您可以计算熵(每个字符的位数),方法是创建一个表,显示现在出现的值的频率,使相对值超出这些绝对的并且为每个元素添加log2(n)* n的结果。
Then you can calculate the entropy (bits per character) by making a table of how often which value appears now, making relative values out of these absolute ones and adding the results of log2(n)*n for each element.
哦,你必须为每个颜色通道(r,g,
Oh, and you have to do this for each color channel (r, g, b) seperately.
对于结果,取每个通道的每个字符的位的平均值,并除以2 ^ 8(假设你有8位每颜色)。
For the result, take the average of the bits per character for the channels and divide it by 2^8 (assuming that you have 8 bit per color).
这篇关于图像熵计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!