Created
October 7, 2015 20:04
-
-
Save sente/ea44cf014c5776a1a5bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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