Posted By

sudarkoff on 08/09/06


Tagged

python image-processing PIL RMS difference


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

mthorn
anayhk
FSX
vkolev


Compare two PIL images in Python


 / Published in: Python
 

URL: http://mail.python.org/pipermail/image-sig/1997-March/000223.html

  1. h1 = Image.open("image1").histogram()
  2. h2 = Image.open("image2").histogram()
  3.  
  4. rms = math.sqrt(reduce(operator.add,
  5. map(lambda a,b: (a-b)**2, h1, h2))/len(h1))

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: rawlyn on May 22, 2009

It's worth noting that this method only compares the histograms of the images, and not the images themselves. The title is extremely misleading.

Posted By: sudarkoff on May 8, 2014

@rawlyn: the above code computes the so-called root-mean-square difference for two images (histogram is like a fingerprint for an image). RMS is a measure of how similar two images are. If RMS is zero the images are identical.

You need to login to post a comment.