图像基本变换---直方图

图像直方图计算函数

[算法说明]

  图像直方图描述的是图像中具有相同灰度级的像素的个数,它是图像灰度的函数。在平面坐标系中,如果用横坐标表示灰度级(0-255),则纵坐标就代表该灰度级的像素的个数。用公式表示如下:

  其中hi表示灰度直方图的分布函数,i表示灰度级,ni表示对应灰度级i的像素数目(这里取8位灰度图)

图像基本变换---直方图_第1张图片

Fig.1直方图示意图

  在图Fig.1中,左边描述的是整个图像像素的灰度级,右上边的表格中,第二行描述的是第一行中灰度级像素出现的个数,依据这个表格绘制直方图如Fig.1中右下图所示。

[函数代码]

        /// 

        /// Get the array of histrgram.

        /// 

        /// The source image.

        /// 

        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;

            }

        }

    }

}


demo 下载: http://www.zealfilter.com/forum.php?mod=viewthread&tid=20&extra=page%3D2

你可能感兴趣的:(图像基本变换)