title: Root mean square difference between two images using Python and PIL
body: <p>I need to have a function like the one found here: <a href="http://effbot.org/zone/pil-comparing-images.htm" rel="noreferrer">http://effbot.org/zone/pil-comparing-images.htm</a> that calculates the root mean square difference between two images. The code looks like this:</p>
  
  <pre><code>import ImageChops
  import math, operator
  
  def rmsdiff(im1, im2):
      "Calculate the root-mean-square difference between two images"
  
      h = ImageChops.difference(im1, im2).histogram()
  
      # calculate rms
      return math.sqrt(reduce(operator.add,
          map(lambda h, i: h*(i**2), h, range(256))
          ) / (float(im1.size[0]) * im1.size[1]))
  </code></pre>
  
  <p>Trying to run this code leads to the following error: TypeError: unsupported operand type(s) for ** or pow(): 'NoneType' and 'int'. That's the matter with it?</p>