views:

69

answers:

1

Hi,

I need to compare two images as fast as possible. I don't need to know the differences or anything else I just need to know if they are the same, yes/no, awesome. What is the fastest way to do this?

Thanks, R.

+1  A: 

If they are expected to be the same, byte-by-bye like @NullUserException mentioned, the easiest solution is to use a hash like Md5. If you'd like to get more advanced, you can get the RGB values of each pixel in the first image and calculate the euclidean distance from the pixels in the second image checking to see if it's below some threshold. Everything is else is not fast :)

Stefan Mai
wouldn't comparing each file byte by byte until a difference is found be much faster than computing an md5 checksum for both?
JoshD
@JoshD: it would certainly be much much faster for images that differ and merely much faster for images that are the same.
GregS
If you're only comparing one file to another, there's no advantage to using a hash. However, if you will be comparing one image to many, the time spent computing the hash is amortized over the multiple comparisons of hash values. Comparing hashes is many times faster than comparing byte for byte because hashes are very small relative to the original data. If you are trying to determine if a new image is already in a large collection of images, compute the hash once and compare many times (store the hash of each image as it is inserted into the collection so it's cheap and easy to get it).
dthorpe