有没有办法改变2图像的像素?

时间:2016-01-06 09:29:55

标签: c++ opencv

enter image description here

enter image description here JPG

我想检查第二张图像,看看像素是否为白色,如果是白色,我应该将其更改为黑色像素,而且我应该能够将第二张图像中同一点的像素更改为第一张图片为黑色或白色.. 例: img at cooridnate(100,100),像素从第二张图像变白,我应该可以将它变成黑色。然后第一个img在相同的cooridnate(100,100)像素将是黑色,我应该能够将其更改为白色。减少噪音。

2 个答案:

答案 0 :(得分:0)

以下代码显示了如何在图像中找到一个点,看它是否为白色,如果是,则将其更改为黑色。

Scalar colourInSecondImage = img2.at<uchar>(y,x);

if(colourInSecondImage .val[0]==255 && colourInSecondImage .val[1]==255 && colourInSecondImage .val[2]==255)
{
    // Then your point is a white point
    img2.at<uchar>(y,x) = Scalar(0,0,0);
}

我对你的问题有点困惑,似乎你想要访问另一张图片中的同一点并将其设置为黑色?还是相同的颜色?无论哪种方式,您将使用与上面的代码相同的方法。将im2更改为img1

答案 1 :(得分:0)

这是循环所有像素值并操纵它们的方法

$(".td-block-span4:nth-child(3)", this).prependTo(item.next());
//or
$item.find(".td-block-span4:nth-child(3)").prependTo(item.next());

////分割频道

 for(int r = 0; r < image.rows; r++) {
        for(int c = 0; c < image.cols; c++) {
           // if pixel is white
           if(image.at<uchar>(r,c) == 255) {
               image.at<uchar>(r,c) = 0;
           }
      }
 }
相关问题