How can I compare two images? I found Python's PIL library, but I do not really understand how it works.
19
votes
Please precise your question : what are you trying to compare ? What did you try ?
- CoMartel
well this doesn't make any sense, that's why I asked. An image is basically an array (2D or 3D, depends if you are in RGB/grayscale), and there a multiple ways to compare 2 images : if you need to see if they are identical, image1-image2 will give you the information. If you need to find the transformation between 2 images, that's another thing.
- CoMartel
2 Answers
17
votes
To check does jpg files are exactly the same use pillow library:
from PIL import Image
from PIL import ImageChops
image_one = Image.open(path_one)
image_two = Image.open(path_two)
diff = ImageChops.difference(image_one, image_two)
if diff.getbbox():
print("images are different")
else:
print("images are the same")