Compare two images to check if they are the same

user2855724 picture user2855724 · Oct 18, 2013 · Viewed 10.4k times · Source

Which is the efficient way to compare two images (Bitmaps), to check if they are the same or not?

I've tried to document me and I've read that I need to re-size both images to around 16x16px, but I don't get the expected result.

I've tried to compare the resized images using .Equals:

    If img1.Equals(img2) then 
        msgbox("are equals!")
    End if

I've seen AForge image library but I can't found any method inside to compare Images.

Is there way to do an efficient Image comparison using .NET classes or 3rd party libs without hardcode a pixel-per-pixel image comparer? If not, any example of a function to compare images?

Answer

Paul picture Paul · Oct 18, 2013

You need to think carefully about your requirements and what equal means. If you are doing a direct pixel by pixel comparison, then you can find numerous .net image classes to help with this (I am not a .net expert but try here Image Comparison for find percentage of similarity between images )

Of course implementing a simple direct image difference is fairly easy. You could even allow for slight differences with difference < threshold, which the tutorial in the above SO answer discusses. Incidentally this answer also mentions SIFT, which I did not realize until after I had mentioned it. SIFT is a good tool depending on your requirements.

The SIFT 3rd party tool is a great way to compare images that can have slight variations, but you might have to make a system call as I am not sure if they provide a .net interface. The definitive website for SIFT implementation is: http://www.cs.ubc.ca/~lowe/keypoints/

I did find this on the internet: http://www.nowozin.net/sebastian/tu-berlin-2006/libsift/ which claims to be a c# implementation.