国产探花免费观看_亚洲丰满少妇自慰呻吟_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#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 凤台县| 丹寨县| 永平县| 霞浦县| 阿坝| 蒲城县| 锡林浩特市| 霞浦县| 扬中市| 伊宁市| 武平县| 峨边| 西乌珠穆沁旗| 汤原县| 富顺县| 隆尧县| 马山县| 鸡泽县| 卓资县| 如东县| 龙江县| 昌乐县| 吉木乃县| 甘南县| 班玛县| 瓮安县| 禹州市| 云浮市| 宝清县| 开阳县| 江西省| 吐鲁番市| 莎车县| 吴忠市| 尼木县| 太仆寺旗| 安溪县| 玉溪市| 安龙县| 朝阳市| 阳泉市|