Last active
August 29, 2015 14:13
-
-
Save djromero/a927ff95825e4c4a29ae to your computer and use it in GitHub Desktop.
Compare two images.
This file contains hidden or 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
# http://effbot.org/zone/pil-comparing-images.htm | |
from PIL import Image | |
import sys | |
import math | |
import operator | |
if len(sys.argv) < 3: | |
print "<image_path> <image_path>".format(sys.argv[0]) | |
sys.exit(1) | |
img1 = sys.argv[1] | |
img2 = sys.argv[2] | |
print img1 | |
print img2 | |
h1 = Image.open(img1).histogram() | |
h2 = Image.open(img2).histogram() | |
rms = math.sqrt(reduce(operator.add, map(lambda a,b: (a-b)**2, h1, h2))/len(h1)) | |
print "Difference (0.0 means images are identical):\n{0}".format(rms) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment