从直方图中获取黑白强度值
我正在尝试从彩色图像中获取黑白直方图数据。然而,我的直方图当前设置仅显示颜色数据,我确信这是我必须在当前数学设置中修改的内容。
// 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 );
}
预先感谢您的任何建议。
I am trying to get black and white histogram data from a color image. However the current setup I have with my histogram only shows me color data I'm sure that it's something that I have to modify in my current math setup.
// 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 );
}
Thanks in advance for any advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有两种方法:
创建
whiteCount
和blackCount
变量。迭代所有像素,如果像素为 (255, 255, 255),则递增whiteCount
;如果像素为 (0, 0, 0),则递增blackCount
。 p>将图像转换为灰度,创建直方图并查看第一个和最后一个 bin。
Here are two methods:
Create
whiteCount
andblackCount
variables. Iterate through all the pixels and incrementwhiteCount
if the pixel is (255, 255, 255) and incrementblackCount
if the pixel is (0, 0, 0).Convert the image to grayscale, create a histogram and look at the first and last bins.