Skip to content
Related Articles

Related Articles

Finding Difference between Images using PIL

Improve Article
Save Article
  • Last Updated : 14 Feb, 2022
Improve Article
Save Article

Python interpreter in itself doesn’t contain the ability to process images and making out a conclusion to it. So, PIL(Python Imaging Library) adds image processing powers to the interpreter. PIL is an open-source library that provides python with external file support and efficiency to process images and their representations. Basically, PIL is designed to access data in the form of images (pixels) to make the analysis faster.

PIL supports image formats like-

  • jpeg
  • tiff
  • png
  • jpg
  • gif

There are a lot of functions that can be performed using PIL, they are-

1) Uploading images

Using PIL, we can load an image and display it. 

Code: After installing the PIL library, run the following code to display any image say abc


from PIL import Image
img1 ='abc.jpg')


The image will display like this after running the code

2) Saving images

Code: For saving image 


from PIL import Image
img1 ='flower.png')'flower.png')

Note: Other functions using PIL – Image processing, difference using ImageChops, downloading, Reading pixels, etc.

Finding the Difference between two images using PIL library

To find the difference, upload 2 images in the interpreter and then using ImageChops find the difference between both of them, output will be self-explanatory.

Images used for difference:




from PIL import Image, ImageChops
img1 ='p.jpg')
img2 ='r.jpg')
diff = ImageChops.difference(img1, img2)
if diff.getbbox():


The extra portions / difference between both image is green in colour.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!