How to get the average intensity value of the red color area in C# using EMGU CV library?

你离开我真会死。 提交于 2019-12-11 23:16:21

问题


Here I used this:

pictureBox1.Image = My_Image.ToBitmap();
byte Red_val = My_Image.Data[0, 0, 2];
MessageBox.Show(Red_val.ToString());

Does this give the average intensity of the red area? How do I get the average intensity value?


回答1:


Your second line:

byte Red_val = My_Image.Data[0, 0, 2];

Will give you the Red Value of the Pixel on the 0th Row and 0th Column. If you want the average Red of the whole picture you should iterate through the Rows and Columns of it and sum up the Channel Data.

 Double Red_avg = 0.0;  
 for (int j = 0; j < My_Image.Cols; j++)
 {
    for (int i = 0; i < My_Image.Rows; i++)
    {
    Red_avg+=My_Image.Data[i, j,2];
    }
 }
Red_avg=Red_avg/(My_Image.Cols*My_Image.Rows);



回答2:


There is Image.GetAverage() method available which will do the job. There also an overload of Image.GetAverage(mask), which will take a mask if you need a non-rectangular region: http://www.emgu.com/wiki/files/1.4.0.0/html/3b71b52b-48a1-a3de-d3f6-75010ef3ff26.htm




回答3:


Have a look at the Image.AvgSdv method in EMGU:

public void AvgSdv( out TColor avg, out MCvScalar sdv )

It "Calculates the average value and standard deviation of array elements, independently for each channel". It will probably be faster than looping through the image yourself.



来源:https://stackoverflow.com/questions/30331784/how-to-get-the-average-intensity-value-of-the-red-color-area-in-c-sharp-using-em

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!