【发布时间】:2025-12-12 22:30:01
【问题描述】:
我有以下 EMGU CV 代码来为灰度图像创建直方图:
Image<Bgr, Byte> img = new Image<Bgr,
Byte>(fileNameTextBox.Text).Resize(400, 400,
Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR, true);
// Convert to grayscale and filter out noise.
Image<Gray, Byte> gray = img.Convert<Gray, Byte>().PyrDown().PyrUp();
DenseHistogram dh = new DenseHistogram(256, new RangeF(0, 255));
dh.Calculate(new Image<Gray, Byte>[] { gray }, false, null);
float[] valHist = new float[256]; // # of bins: 256
dh.MatND.ManagedArray.CopyTo(valHist, 0);
float total = 0F;
for (int ii = 0; ii < 256; ii++)
{
total += valHist[ii];
}
MessageBox.Show("Bins total: " + total);
我用下面的图像运行上面的代码(原始图像不包含它周围的边框 - 我在这里添加了它以进行分界):
图像为 384 x 282,即 108,288 像素。但是直方图的 256 个 bin 的内容总和为 4,724(如MessageBox 代码所示)。总数不应该是108,288吗? (也许我缺少直方图概念的基础知识?)
(免责声明:我是图像处理和 EMGU CV 的新手,虽然我做过研究,但这里关于 SO 的 EMGU 问题相对较少,网络上的所有其他内容似乎都是这里问题的副本。 )
【问题讨论】:
标签: opencv image-processing emgucv