I am creating a simple script to check if images are the same or different.
My code works for the jpg files but not for the png files.
For some reason, my code below thinks that the below png:
is the same as below png
from PIL import Image, ImageChops
img1 = Image.open('./1.png')
img2 = Image.open('./2.png')
img3 = Image.open('./A.jpg')
img4 = Image.open('./B.jpg')
diff1 = ImageChops.difference(img3, img4)
diff = ImageChops.difference(img2, img1)
print(diff.getbbox())
if diff.getbbox():
diff.show() # does not work for me. should show image if they are different
print(diff1.getbbox())
if diff1.getbbox():
diff1.show() # this works not sure why the PNG files do not
I am running this on Ubuntu. I am not sure what I am doing wrong. Any help would be great thanks!
Working code after @Mark's help: https://github.com/timothy/image_diff/blob/master/test.py




