Win8 Metro(C#)数字图像处理--3.3图像直方图计算

原文: Win8 Metro(C#)数字图像处理--3.3图像直方图计算

/// <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;
            }
        }
    }
}
最后,分享一个专业的图像处理网站(微像素),里面有不少源代码下载:
相关文章
相关标签/搜索