Comparing (similar) images with Python/PIL
- by Attila Oláh
I'm trying to calculate the similarity (read: Levenshtein distance) of two images, using Python 2.6 and PIL.
I plan to use the python-levenshtein library for fast comparison.
Main question:
What is a good strategy for comparing images? My idea is something like:
Convert to RGB (transparent - white) (or maybe convert to monochrome?)
Scale up the smaller one to the larger one's size
Convert each channel (= the only channel, if converted to monochrome) to a sequence (item value = color value of the pixel)
Calculate the Levenshtein distance between the two sequences
Of course, this will not handle cases like mirrored images, cropped images, etc. But for basic comparison, this should be useful.
Is there a better strategy documented somewhere?