Created
August 24, 2021 07:29
-
-
Save oofnivek/7be793c0dcd7185bc49c57d988ecbb7d 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 | |
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