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
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
unity實(shí)現(xiàn)文字滾動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了unity實(shí)現(xiàn)文字滾動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-02-02
C#實(shí)現(xiàn)二維數(shù)據(jù)數(shù)組導(dǎo)出到Excel的詳細(xì)過程
將數(shù)據(jù)庫(kù)查詢出來的數(shù)據(jù)導(dǎo)出并生成?Excel?文件,是項(xiàng)目中經(jīng)常使用的一項(xiàng)功能,本文將介紹通過數(shù)據(jù)集生成二維數(shù)據(jù)數(shù)組并導(dǎo)出到?Excel,文中有詳細(xì)的代碼供大家參考,需要的朋友可以參考下2024-09-09
C# Socket通信的實(shí)現(xiàn)(同時(shí)監(jiān)聽多客戶端)
這篇文章主要介紹了C# Socket通信的實(shí)現(xiàn)(同時(shí)監(jiān)聽多客戶端),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-04-04
深入DropDownList用法的一些學(xué)習(xí)總結(jié)分析
本篇文章是對(duì)DropDownList的用法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
C#簡(jiǎn)單實(shí)現(xiàn)表達(dá)式目錄樹(Expression)
表達(dá)式目錄樹以數(shù)據(jù)形式表示語言級(jí)別代碼。數(shù)據(jù)存儲(chǔ)在樹形結(jié)構(gòu)中。表達(dá)式目錄樹中的每個(gè)節(jié)點(diǎn)都表示一個(gè)表達(dá)式。這篇文章給大家介紹C#簡(jiǎn)單實(shí)現(xiàn)表達(dá)式目錄樹(Expression),需要的朋友參考下吧2017-11-11
Unity實(shí)現(xiàn)簡(jiǎn)單場(chǎng)景分層移動(dòng)
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)簡(jiǎn)單場(chǎng)景分層移動(dòng),分為前景、場(chǎng)景、背景等,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09

