1

http://www.huahongquan.com/index.php/blog/x-ly-nh-video-s/11-opencv-topic-02-get-histogram

我使用他的代码为我的图像计算一维直方图。问题是,范围设置为 0-255,但是当我打印值时,我得到的像素值超过 255(即 15842、73132)

我需要在代码中添加一些内容吗?

@George 这就是我打印值并使用 Mat 的方式。

for(int i = 0 ; i < 256 ; i++){
cout << "Value"  << i << " = " << histogram.at<float>(i) << endl;        
}
4

1 回答 1

8

我认为您所说的 0-255 范围是 bin 的数量,而不是像素值。

histogram.at<float>(i)是落入 bin 的像素数,i因此它可以是从 0 到输入图像大小(宽 * 高)的任意整数。

例如,输出Value254 = 4182意味着有 4182 个像素,其值为 254。

于 2013-01-15T13:15:27.273 回答