量化图像的值

发布于 2024-12-19 13:51:31 字数 1411 浏览 4 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荭秂 2024-12-26 13:51:31

您正在使用间隔,但这会遗漏任何恰好是 16 倍数的值。您应该使用半闭间隔:

if (Ib.at(i) >= j && Ib.at(i) < j + 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:

if (Ib.at(i) >= j && Ib.at(i) < j + 16)
//           ^^
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文