0

I need to compare an image with various images, and do something if they're equal (I don't need any image recognition whatsoever, I just need to compare two 100% perfectly equal images), well, by searching on stackoverflow I concluded that my best bet would be encoding my image to base64, and then comparing the string with another string.

I need to compare an image with another image, then another image, then another image and so on, stopping whenever I find a perfect match. My plan is to store every 64 string in an array, then compare the target image which each item, the plan is great, in theory, however something worries me, the length of the string is 852754 characters, that means it will be very, very slow. Are there any alternatives ways of doing that?

I would even be willing to save the images in my computer, if that would help anything, there are about 200 or 300 of them, it's not that much.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Aloc1234
  • 155
  • 2
  • 6

3 Answers3

1

This can be done by hashing the string (of course, the entropy here might be a problem given the 852754-length string) with something like an MD5 implementation. You could also conceivably use checksums (something like a crc32 function) which ought to be faster.

Use your favorite method for generating a hash and after you generate a couple, simply compare hashes (which will be much faster).

David Titarenco
  • 32,662
  • 13
  • 66
  • 111
  • +1 This is good for a first approximation. Of course, images can be pixel-to-pixel the same but still have different hashes, or even different lengths. – Brock Adams Feb 16 '13 at 23:49
0

This is why we have one-way hashing algorithms! You should find a library to hash the image data (e.g. md5). You can store these easily and compare quickly.

When you have an md5 match you can then compare the data just to be sure (it's possible but very unlikely that there are collisions giving false matches).

Joe
  • 46,419
  • 33
  • 155
  • 245
0

If I well understtod your question : you can use getBase64Image() method on a var myimage = new Image() element

epsilones
  • 11,279
  • 21
  • 61
  • 85