量化图像的值
我正在 Linux 上的 OpenCV 中工作。我正在尝试量化长度为 100 的向量 Ib、Ig、Ir 的值。
for (int i=0;i<img31->height;i++)
{
for (int j=0;j<img31->width;j++)
{
Ib.push_back(((uchar*)(img31->imageData+((img31->width*3)*i)))[j*3]);
Ig.push_back(((uchar*)(img31->imageData+((img31->width*3)*i)))[j*3+1]);
Ir.push_back(((uchar*)(img31->imageData+((img31->width*3)*i)))[j*3+2]);
}
}
int g_hist11[16]={0},b_hist11[16]={0},r_hist11[16]={0};
//Quantization code
for (int i=0;i<Ig.size();i++)
{
int j=0;
while(j<256)
{
if (Ib.at(i)>j && Ib.at(i)<j+16)
{
b_hist11[(Ib.at(i)%16)]=b_hist11[(Ib.at(i)%16)]+1;
}
if (Ig.at(i)>j && Ig.at(i)<j+16)
{
g_hist11[(Ig.at(i)%16)]=g_hist11[(Ig.at(i)%16)]+1;
}
if (Ir.at(i)>j && Ir.at(i)<j+16)
{
r_hist11[(Ir.at(i)%16)]=r_hist11[(Ir.at(i)%16)]+1;
}
j=j+16;
}
}
但是当我尝试添加存储在数组 g_hist11、r_hist11、b_hist11 中的计数时,它们不会出现100.
I am working in OpenCV on Linux.I am trying to quantize values of vectors Ib,Ig,Ir which are of length 100.
for (int i=0;i<img31->height;i++)
{
for (int j=0;j<img31->width;j++)
{
Ib.push_back(((uchar*)(img31->imageData+((img31->width*3)*i)))[j*3]);
Ig.push_back(((uchar*)(img31->imageData+((img31->width*3)*i)))[j*3+1]);
Ir.push_back(((uchar*)(img31->imageData+((img31->width*3)*i)))[j*3+2]);
}
}
int g_hist11[16]={0},b_hist11[16]={0},r_hist11[16]={0};
//Quantization code
for (int i=0;i<Ig.size();i++)
{
int j=0;
while(j<256)
{
if (Ib.at(i)>j && Ib.at(i)<j+16)
{
b_hist11[(Ib.at(i)%16)]=b_hist11[(Ib.at(i)%16)]+1;
}
if (Ig.at(i)>j && Ig.at(i)<j+16)
{
g_hist11[(Ig.at(i)%16)]=g_hist11[(Ig.at(i)%16)]+1;
}
if (Ir.at(i)>j && Ir.at(i)<j+16)
{
r_hist11[(Ir.at(i)%16)]=r_hist11[(Ir.at(i)%16)]+1;
}
j=j+16;
}
}
But when I try to add the counts stored in the arrays g_hist11,r_hist11,b_hist11 they do not come out to 100.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用开间隔,但这会遗漏任何恰好是 16 倍数的值。您应该使用半闭间隔:
You are using open intervals but this misses out any values that are exact multiples of 16. You should be using half-closed intervals: