如何使用 EMGU CV 库在 C# 中获取红色区域的平均强度值?

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

这里我用的是这个:

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

这是否给出了红色区域的平均强度?我如何获得平均强度值?

你的第二行:

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

将为您提供第 0 行第 0 列像素的红色值。 如果你想要整张图片的平均红色,你应该遍历它的行和列并总结通道数据。

 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);

看看 EMGU 中的 Image.AvgSdv 方法:

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

"Calculates the average value and standard deviation of array elements, independently for each channel"。它可能比自己循环浏览图像更快。

Image.GetAverage() 方法可以完成这项工作。还有一个 Image.GetAverage(mask) 的重载,如果你需要一个非矩形区域,它会带一个掩码:http://www.emgu.com/wiki/files/1.4.0.0/html/3b71b52b-48a1-a3de-d3f6-75010ef3ff26.htm