Skip to content

Instantly share code, notes, and snippets.

@oofnivek
Created August 24, 2021 07:29
Show Gist options
  • Save oofnivek/7be793c0dcd7185bc49c57d988ecbb7d to your computer and use it in GitHub Desktop.
Save oofnivek/7be793c0dcd7185bc49c57d988ecbb7d to your computer and use it in GitHub Desktop.
import sys
from PIL import Image
def compare_pixels(png1, png2):
pixels1 = list(png1.getdata())
pixels2 = list(png2.getdata())
if len(pixels1) != len(pixels2):
return -1 # different pixel count
match = 0
mismatch = 0
for i in range(0, len(pixels1)):
if pixels1[i] == pixels2[i]:
match = match + 1
else:
mismatch = mismatch + 1
return match/(match+mismatch)
png1 = Image.open(sys.argv[1])
png2 = Image.open(sys.argv[2])
print(compare_pixels(png1,png2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment