Skip to content

Instantly share code, notes, and snippets.

@sente
Created October 7, 2015 20:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sente/ea44cf014c5776a1a5bf to your computer and use it in GitHub Desktop.
Save sente/ea44cf014c5776a1a5bf to your computer and use it in GitHub Desktop.
import sys
import PIL
from PIL import ImageChops
from functools import reduce
import math, operator
def rmsdiff(im1, im2):
"Calculate the root-mean-square difference between two images"
h = ImageChops.difference(im1, im2).histogram()
print h
# 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]))
if __name__ == '__main__':
a= PIL.Image.open(sys.argv[1])
b= PIL.Image.open(sys.argv[2])
print (rmsdiff(a,b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment