本文展示图像均值和方差计算实例,分别实现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();