问题
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