-2
  1. numerical difference is expected as positive or negative with decimal places
  2. compare the visual appearance of each image, not their binary contents

for example:
file1.png & file2.gif
diff 0.23
time elapsed 0.843

I have tried


from PIL import Image
from PIL import ImageChops

...

one = Image.open("file1.png")  
two = Image.open("file2.gif")  
diff = ImageChops.difference(one, two)  
print(diff)  

But ImageChops does not work for comparing .gif and .png files. Error is


python3.8/site-packages/PIL/ImageChops.py", line 102, in difference  
    return image1._new(image1.im.chop_difference(image2.im))  
ValueError: images do not match  

Will imagemagick or numpy work? has to support .png, .gif (.jpg, .bmp are optional)

Ridhwaan Shakeel
  • 981
  • 1
  • 20
  • 39
  • Are you certain the error is due to different file formats? Or could it be that images are of different size or using different color format or one of many other possible issues? – NotAName Oct 19 '20 at 23:44
  • Try running `print(one.format, one.size, one.mode)` and the same for the second image. – NotAName Oct 19 '20 at 23:47
  • try cv2.matchTemplate() – fmw42 Oct 19 '20 at 23:59

1 Answers1

0

Try printing the modes of the images.

print(one.mode)
print(two.mode)

If those two modes != are not equal to each other, then it can bomb out as you are seeing.

Bill Maca
  • 1
  • 2