Click here to Skip to main content
14,237,525 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,

Is there a way to compare 2 images and also highlight the differences. I have looked at the following article and I want to highlight the differences also.
Comparing Images using GDI+[^]

Thank you
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

I hope you already learned how to lock bitmap in memory and work with raw image data to get reasonable performance? If not, see the code sample here: http://msdn.microsoft.com/en-us/library/5ey6h79d.aspx[^]. First thing to know: never use GetPixel/SetPixel for this is similar purposes, due to performance issues. Be careful with possibly different pixel formats, see the property System.Drawing.Bitmap.PixelFormat. In principle, you can compare different formats, just see the description of each to interpret them correctly — you work on the low level in all such processing.

Now, what to do with that?

The naive question if to subtract one image from another per component and optionally normalize the result. It will work.
One problem is: some values are lower in one image, some are lower on the other one. One approach is: it you have two images, I1 and I2, subtract using signed result type and change negative values to zero; create two differential images I1-I2 and I2-I1; alternatively, subtract and get the absolute value.

For more sophisticated processing, use AForge.NET: http://www.aforgenet.com/[^].

—SA
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

You can possibly compare them pixel by pixel and if Image1Pixel has different value than Image2Pixel, you can change the color by changing pixel values. This should be done in using unsafe code to get better performance. Although be sure to manage the memory and other resources wisely since .Net won't do that for you.

This surely assumes that the images are of same size. If they are of different sizes, you will need to do some more work. There are a lot of tools available on web and a lot to read as well. I think you should spend time researching for "Image comparison algorithms" and choose the best fit for you.

Just noticed, since you have already found an article which possibly suits you, ask a question under article forum so that author can help you out.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100