Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am a s/w developer. My question is how to compare two images and visualize the output by comparing its pixel matching. I also want to show the unmatched pixel area :confused::confused:
Posted
Updated 21-Oct-10 4:01am
v2

This code may help you

try like this...

Bitmap img1 = new Bitmap("c:\\rajesh.jpg");
          Bitmap img2 = new Bitmap("c:\\rajesh.jpg");
          Color Myc1; Color Myc2;
          for (int i = 0; i < img1.Height; i++)
              for (int j = 0; j < img2.Width; j++)
              {
                  Myc1 = img1.GetPixel(i, j);
                  Myc2 = img2.GetPixel(i, j);
                  if ((Myc1.R != Myc2.R) || (Myc1.G != Myc2.G) || (Myc1.B != Myc2.B))
                      MessageBox.Show ("Found Mismatch");
              }
 
Share this answer
 
Comments
meenavinaykumar 3-Nov-10 2:06am    
thanks for ur kind reply.but i want to visualise the unmatched pixel area.will u help me?
Make a copy of one of the bitmaps - so that you can modify it (in memory) without destroying your source images.

Use LockBits() on both bitmaps to get access to the raw bitmap data.

Iterate the whole bitmap array, indexing both images in parallel, comparing bytes between images. Where the bytes are the same, write 0 to the copy; where the bytes are different, write 255 to the copy.

Now, you can view the copy, and wherever the images match you'll get black and wherever they differ you'll get white.

Instead of writing 255 where bytes differ, you could write the original value - but if it has a low value, it'll be hard to tell a 'real' black pixel from a black 'pixels match' pixel.

Note that this operation assumes iterating the array as bytes. Depending on the bit-depth of the image this may be inappropriate (for example, 1 bpp images) or inconvenient (e.g. 32 bpp images, you could process a whole pixel at a time, instead of a single color component at a time).

If you can process a whole pixel at a time, there might be a 'highly improbably' color that you could use as the 'pixels match' indicator, that would be unlikely to occur in a real image.
 
Share this answer
 
Comments
meenavinaykumar 3-Nov-10 2:04am    
thank for u kind reply but i need the code.will u please help me?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900