国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#圖像處理之圖像均值方差計算的方法

2020-01-24 01:56:14
字體:
來源:轉載
供稿:網友

本文實例講述了C#圖像處理之圖像均值方差計算的方法。分享給大家供大家參考。具體如下:

//本函數均是基于RGB顏色空間計算//定義圖像均值函數(RGB空間)public double AnBitmap(Bitmap a){  double V = 0;  Rectangle rect = new Rectangle(0, 0, a.Width, a.Height);  System.Drawing.Imaging.BitmapData bmpData = a.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);  unsafe  {   byte* pIn = (byte*)bmpData.Scan0.ToPointer();   byte* P;   int R, G, B;   double meanvalue = 0, sum = 0;    int stride = bmpData.Stride;   for (int y = 0; y < a.Height; y++)   {     for (int x = 0; x < a.Width; x++)     {     P = pIn;     B = P[0];     G = P[1];     R = P[2];     sum += B * 0.114 + G * 0.587 + R * 0.299;     pIn += 3;     }     pIn += stride - a.Width * 3;   }   meanvalue = sum / (a.Width * a.Height);   V = meanvalue;  }  a.UnlockBits(bmpData);  return V;  //返回圖像均值V}//定義圖像統計方差函數(RGB空間)public double AnCONBitmap(Bitmap a,double meanvalue){  double V = 0;  Rectangle rect = new Rectangle(0, 0, a.Width, a.Height);  System.Drawing.Imaging.BitmapData bmpData = a.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);  unsafe  {   byte* pIn = (byte*)bmpData.Scan0.ToPointer();   byte* P;   int R, G, B;   double conv = 0, sum = 0;   int stride = bmpData.Stride;   for (int y = 0; y < a.Height; y++)   {     for (int x = 0; x < a.Width; x++)     {     P = pIn;     B = P[0];     G = P[1];     R = P[2];     sum += (B * 0.114 + G * 0.587 + R * 0.299 - meanvalue) * (B * 0.114 + G * 0.587 + R * 0.299 - meanvalue);     pIn += 3;     }     pIn += stride - a.Width * 3;    }    conv = sum / (a.Width * a.Height-1);   V = conv;  }  a.UnlockBits(bmpData);  return V;  //返回圖像方差V}

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 松阳县| 重庆市| 长治市| 集贤县| 靖江市| 焉耆| 分宜县| 南召县| 电白县| 虎林市| 丰原市| 辽源市| 阳城县| 中方县| 北宁市| 德钦县| 英吉沙县| 德惠市| 南涧| 太湖县| 北票市| 桦南县| 刚察县| 凤凰县| 牙克石市| 建始县| 五常市| 南木林县| 民县| 荥阳市| 寻乌县| 梅河口市| 乌拉特前旗| 分宜县| 和顺县| 新田县| 武乡县| 永丰县| 福建省| 巫山县| 子长县|