Comparing (similar) images with Python/PIL

Posted by Attila Oláh on Stack Overflow See other posts from Stack Overflow or by Attila Oláh
Published on 2010-04-08T21:53:40Z Indexed on 2010/04/08 22:13 UTC
Read the original article Hit count: 500

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?

© Stack Overflow or respective owner

Related posts about python

Related posts about pil