3

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?

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • 1
    How do you define "equal"? Same RGB values at every pixel? Do you allow for a slight difference? Surely it must be rather trivial to store every pixel's RGB value into a list and compare those. – Jeroen Vannevel Oct 18 '13 at 01:18
  • what size are these images? – Ňɏssa Pøngjǣrdenlarp Oct 18 '13 at 03:40
  • A pixel per pixel compare is the only way (even external libs etc will do it) and is FAST. If you put the code into a C# dll, you can work with `LockBits` and `unsafe`. I tried it once and came to something like 50-70ms for a 24MB image on a very old Turion CPU. – igrimpe Oct 18 '13 at 05:02
  • the size of the images are 1920x1080 but 16x16 when resized (if I need to resize them)... –  Oct 18 '13 at 16:25

1 Answers1

1

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.

Community
  • 1
  • 1
Paul
  • 7,155
  • 8
  • 41
  • 40