How to spot differences between images using Python

How to spot differences between images using Python

Yesterday Sep 27th was my all time Icon , Francesco Totti's birthday and I came across a very interesting video on YouTube about Python, So I decided to combine these 2 and come up with a article.

Can you spot 4 differences in these images?

No alt text provided for this image
No alt text provided for this image

Of course you can do :) ,but there is python package with which you can spot the differences like having a piece of cake.

First you need to install "pillow" package , either using pip install or whatever way you desire , then copy 2 images to the folder in which your Python code is placed , after that you can easily run the following lines of codes defining 2 images and then compare them ,

from PIL import Image , ImageChops
Img1 = Image.open("01.jpg")
Img2 = Image.open("02.jpg")
diff = ImageChops.difference(Img1 , Img2)
if diff.getbbox():
    diff.show()

The code would give you an image showing differences , as easy as that. :))))

No alt text provided for this image


Seema Patel, PhD

Data Analyst | Bioinformatician | Medical Writer | Microbiologist | Molecular Biologist I Thought leader

1 年

I tried with my sample images, and its exciting to spot the differences. Thank you Milad.

要查看或添加评论,请登录

Milad Firouzi的更多文章

社区洞察

其他会员也浏览了