C#图像均值和方差计算实例

本文展示图像均值和方差计算实例,分别实现RGB图像和8位单通道图像的计算方法

实现代码如下:

#region 方法 RGB图像均值 直接操作内存快
        /// <summary>
        /// 定义RGB图像均值函数
        /// </summary>
        /// <param name="bmp"></param>
        /// <returns></returns>
        public static double MyBitmapMeanValue(Bitmap bmp)
        {
            Bitmap bmpNew = MyBitmapClone(bmp);//需要克隆要不原图像变化了
            double returnValue = 0;
            Rectangle rect = new Rectangle(0, 0, bmpNew.Width, bmpNew.Height);
            //锁定bitmap到内存
            System.Drawing.Imaging.BitmapData bmpData = bmpNew.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            unsafe
            {
                byte* pIn = (byte*)bmpData.Scan0.ToPointer();
                

猜你喜欢

转载自blog.csdn.net/qq_30725967/article/details/132179892
今日推荐