/// <summary>
/// Get the array of histrgram.
/// </summary>
/// <param name="src">The source image.</param>
/// <returns></returns>
public static int[] GetHistogramArray(WriteableBitmap src) ////34 图像直方图计算
{
if (src != null)
{
int[] histogram = new int[256];
int gray = 0;
byte[] temp = src.PixelBuffer.ToArray();
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);
histogram[gray]++;
}
return histogram;
}
else
{
return null;
}
}
}
}
最后,分享一个专业的图像处理网站(微像素),里面有很多源代码下载:

本文介绍了一种计算图像直方图的方法,通过将RGB图像转换为灰度图像,并统计每个灰度级出现的频率来获取直方图。适用于图像处理初学者及开发者。
843

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



