Skip to content

Instantly share code, notes, and snippets.

@djromero
Last active August 29, 2015 14:13
Show Gist options
  • Save djromero/a927ff95825e4c4a29ae to your computer and use it in GitHub Desktop.
Save djromero/a927ff95825e4c4a29ae to your computer and use it in GitHub Desktop.
Compare two images.
# 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