【问题标题】:Getting black and white intensity values from a histogram从直方图中获取黑白强度值
【发布时间】:2011-08-12 15:30:31
【问题描述】:

我正在尝试从彩色图像中获取黑白直方图数据。但是,我的直方图当前设置仅显示颜色数据,我确信这是我必须在当前数学设置中修改的内容。

// Current setup on how to render histogram data to the screen with hist being the calculated histogram
histimg = Mat::zeros(200, 320, CV_8UC3)
int binW = histimg.cols / 16;
Mat buf(1, 16, CV_8UC3);
for( int i = 0; i < 16; i++ )
{
    buf.at<Vec3b>(i) = Vec3b(saturate_cast<uchar>(i*180./16), 255, 255);
}
cvtColor(buf, buf, CV_HSV2BGR);

for( int i = 0; i < 16; i++ )
{
    int val = saturate_cast<int>(hist.at<float>(i)*histimg.rows/255);
    rectangle( histimg, Point(i*binW,histimg.rows),
        Point((i+1)*binW,histimg.rows - val),
        Scalar(buf.at<Vec3b>(i)), -1, 8 );
}

提前感谢您的任何建议。

【问题讨论】:

  • 我不确定你的意思是什么我正在尝试从彩色图像中获取黑白直方图数据。你的意思是你想要灰度强度的直方图的彩色图像?或者您是否尝试以黑白方式绘制直方图?此外,计算机视觉中的“黑白”与电视中的不同。在电视上,它意味着各种灰度。在我们的世界中,它是代表黑色或白色的两个二进制值之一。
  • 我有一张用于创建直方图的彩色图像。根据我上面的数学计算,我可以获得各种红色、绿色和蓝色的阴影以及它们的强度值。我想对黑色、(0、0、0)和白色(255、255、255)颜色值做同样的事情。

标签: image-processing opencv histogram


【解决方案1】:

这里有两种方法:

  1. 创建whiteCountblackCount 变量。遍历所有像素,如果像素为 (255, 255, 255),则增加 whiteCount,如果像素为 (0, 0, 0),则增加 blackCount

  2. 将图像转换为灰度,创建直方图并查看第一个和最后一个 bin。

【讨论】:

  • 第二种方法似乎是最好的方法。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-03
  • 2011-05-23
  • 2015-09-19
  • 2016-06-20
  • 2012-07-01
  • 2014-01-01
相关资源
最近更新 更多