Ask Your Question
1

Comparing two similar images

asked Dec 4 '12

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

Preview: (hide)

2 answers

Sort by » oldest newest most voted
3

answered Dec 4 '12

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.

Preview: (hide)

Comments

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 (Dec 5 '12)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?

0

answered Dec 5 '12

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;

     ele1=cvGet2D(img1,i,j);
     ele2=cvGet2D(img2,i,j);

     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.

Preview: (hide)

Question Tools

Stats

Asked: Dec 4 '12

Seen: 3,566 times

Last updated: Dec 05 '12