C#圖像處理之圖像均值方差計(jì)算的方法
更新時(shí)間:2015年04月24日 10:28:14 作者:滄海一粟……
這篇文章主要介紹了C#圖像處理之圖像均值方差計(jì)算的方法,涉及C#圖像均值方差的計(jì)算技巧,需要的朋友可以參考下
本文實(shí)例講述了C#圖像處理之圖像均值方差計(jì)算的方法。分享給大家供大家參考。具體如下:
//本函數(shù)均是基于RGB顏色空間計(jì)算 //定義圖像均值函數(shù)(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 } //定義圖像統(tǒng)計(jì)方差函數(shù)(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#程序設(shè)計(jì)有所幫助。
相關(guān)文章
C#實(shí)現(xiàn)WPS文件轉(zhuǎn)PDF格式的方法示例
這篇文章主要介紹了C#實(shí)現(xiàn)WPS文件轉(zhuǎn)PDF格式的方法,涉及C#針對office組件的相關(guān)引用與操作技巧,需要的朋友可以參考下2017-11-11C#結(jié)合數(shù)據(jù)庫實(shí)現(xiàn)驗(yàn)證識別ID卡內(nèi)容的方法
這篇文章主要介紹了C#結(jié)合數(shù)據(jù)庫實(shí)現(xiàn)驗(yàn)證識別ID卡內(nèi)容的方法,非常實(shí)用的功能,需要的朋友可以參考下2014-07-07C#禁止textbox復(fù)制、粘貼、剪切及鼠標(biāo)右鍵的方法
這篇文章主要介紹了C#禁止textbox復(fù)制、粘貼、剪切及鼠標(biāo)右鍵的方法,涉及C#針對窗口消息的處理技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09C# Distinct和重寫IEqualityComparer時(shí)要知道的二三事
這篇文章主要給大家介紹了關(guān)于C# Distinct和重寫IEqualityComparer時(shí)要知道的二三事,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06