Ask Your Question

Comparing two similar images

asked 2012-12-04 07:50:20 -0600

PTR gravatar image

I'm just getting started with OpenCV and I want to compare two similar images.There is just one difference between the two images.How could I capture the difference and get it's pixel like RGB or HSV.

Thanks a lot

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2012-12-04 08:21:09 -0600

Michael Burdinov gravatar image

Are those images identical, outside of this difference you are searching for? If yes, you can use != operator like this:

Mat binary_image = (your_image1 != your_image2);

This will create image (called binary_image). Value of its pixel will be 0 your images are same in this pixel. If they are not the same then value of appropriate pixel will be 255.

If those images are not identical but only 'similar' the problem will be much more difficult.

edit flag offensive delete link more


Thank you for your answer. Those images are identical,and they are color images. I wish to get the difference's orginal pixel,but not change it.

PTR gravatar imagePTR ( 2012-12-04 20:11:06 -0600 )edit

I am not sure I understand what is "difference's original pixel". Do you mean that those images differ in exactly one pixel and you want to know its coordinates?

Michael Burdinov gravatar imageMichael Burdinov ( 2012-12-05 05:02:21 -0600 )edit

answered 2012-12-05 04:51:37 -0600

Haris gravatar image

I think for these you need to scan through each pixel in the image and compare it. You can access pixel value using the below code

for(int i=0; i<img1->height; i++)      //img1->height=img21->height
  for(int j=0; j<img1->width; j++)     //img1->width=img2->width
     CvScalar ele1;
     CvScalar ele2;


     if(ele1.val[0]==ele2.val[0]) //Blue channel
        // do some operation

     if(ele1.val[1]==ele2.val[1]) //Green channel
        // do some operation

     if(ele1.val[2]==ele2.val[2]) //Red channel
        // do some operation


Hope these helpful.

edit flag offensive delete link more

Question Tools


Asked: 2012-12-04 07:50:20 -0600

Seen: 3,289 times

Last updated: Dec 05 '12