C#圖像處理之圖像均值方差計算的方法
更新時間:2015年04月24日 10:28:14 作者:滄海一粟……
這篇文章主要介紹了C#圖像處理之圖像均值方差計算的方法,涉及C#圖像均值方差的計算技巧,需要的朋友可以參考下
本文實例講述了C#圖像處理之圖像均值方差計算的方法。分享給大家供大家參考。具體如下:
//本函數(shù)均是基于RGB顏色空間計算
//定義圖像均值函數(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)計方差函數(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è)計有所幫助。
相關(guān)文章
C#實現(xiàn)二維數(shù)據(jù)數(shù)組導出到Excel的詳細過程
將數(shù)據(jù)庫查詢出來的數(shù)據(jù)導出并生成?Excel?文件,是項目中經(jīng)常使用的一項功能,本文將介紹通過數(shù)據(jù)集生成二維數(shù)據(jù)數(shù)組并導出到?Excel,文中有詳細的代碼供大家參考,需要的朋友可以參考下2024-09-09
C# Socket通信的實現(xiàn)(同時監(jiān)聽多客戶端)
這篇文章主要介紹了C# Socket通信的實現(xiàn)(同時監(jiān)聽多客戶端),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-04-04
深入DropDownList用法的一些學習總結(jié)分析
本篇文章是對DropDownList的用法進行了詳細的分析介紹,需要的朋友參考下2013-06-06
C#簡單實現(xiàn)表達式目錄樹(Expression)
表達式目錄樹以數(shù)據(jù)形式表示語言級別代碼。數(shù)據(jù)存儲在樹形結(jié)構(gòu)中。表達式目錄樹中的每個節(jié)點都表示一個表達式。這篇文章給大家介紹C#簡單實現(xiàn)表達式目錄樹(Expression),需要的朋友參考下吧2017-11-11

