What's the best approach to comparing two images with php and the Graphic Draw (GD) Library?This is the scenario:
I have an image, and I want to find which image of a given set is the most similar to it.The most similar image is in fact the same image, not pixel perfect match but the same image.I've dramatised the difference between the two images with the number one on the example just to ease the understanding of what I meant.Even though it brought no consistent results, my approach was to reduce the images to 1px using the imagecopyresampled function and see how close the RGB values where between images. The sum of the values of deducting each red, green and blue decimal equivalent value from the red, green and blue decimal equivalent value of the possible match gave me a dissimilarity index that, even though it didn't work as expected since not always the most RGB similar image was the target image, I could use to select an image from the available targets. Here's a sample of the output when comparing 4 images against a target image, in this case the apple logo, that matches one of them but is not exactly the same:Original image:
iMagick,