I want to compare two images and then decide whether they are the same or not but the PIL library is not able to tell me the correct result. Even I use both ways to compare them it returns true for two different grayscale images.
difference = ImageChops.difference(image1.convert('L'), image2.convert('L'))
if not difference.getbbox() and list(image1.convert('L').getdata()) == list(image2.convert('L').getdata()):
I am using it in this manner but I couldn't handle this problem.
These are the example images for that situation:
Your images have got a superfluous alpha channel. It appears to work if you discard that.
#!/usr/bin/env python3
from PIL import Image, ImageChops
im1 = Image.open('LQk4R.png').convert('L')
im2 = Image.open('gKx4l.png').convert('L')
diff = ImageChops.difference(im1,im2)
diff.show()
In IPython
:
In [13]: diff.getbbox()
Out[13]: (0, 0, 220, 63)
In [14]: im1.getdata() == im2.getdata()
False
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.