[函数代码]
/// <summary>
/// Entropy of one image.
/// </summary>
/// <param name="src">The source image.</param>
/// <returns></returns>
public static double GetEntropy(WriteableBitmap src)
{
double entropy = 0;
if (src != null)
{
int w = src.PixelWidth;
int h = src.PixelHeight;
byte[] temp = src.PixelBuffer.ToArray();
int[] countTemp=new int[256];
int gray = 0;
for (int i = 0; i < temp.Length; i += 4)
{
gray = (int)(temp[i] * 0.114 + temp[i + 1] * 0.587 + temp[i + 2] * 0.299);
countTemp[gray]++;
}
for (int i = 0; i < 256;i++)
{
if (countTemp[i] != 0)
{
entropy += (double)(-((countTemp[i] / (w * h)) * Math.Log10(countTemp[i] / (w * h))));
}
else
continue;
}
return entropy;
}
else
{
return 0;
}
}
最后,分享一个专业的图像处理网站(微像素),里面有很多源代码下载:

本文介绍了一种计算图像熵的方法,该方法将RGB图像转换为灰度图像,并通过统计灰度值频率来计算图像熵。此外,还提供了一个用于图像处理的专业网站链接。
2370

被折叠的 条评论
为什么被折叠?



