Python PIL | ImageChops.add_modulo() and ImageChops.difference() method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities.
ImageChops.add_modulo() method –
This method is used to add two images without clipping them unlike ImageChops.add() which clips the images.
Syntax: ImageChops.add_modulo(image1, image2)
Parameters:
image1 is the first image
image2 is the second imageReturn Value: It returns an Image.
Note: Both the images should be of same MODE.
# This will import Image and ImageChops modulesfrom PIL import Image, ImageChops # Opening Imagesim = Image.open(r"C:\Users\Admin\Pictures\download.png")im2 = Image.open(r"C:\Users\Admin\Pictures\images.PNG") # here adding image1 and image2im3 = ImageChops.add_modulo(im, im2) # showing resultant imageim3.show() |
Output:
ImageChops.difference() method –
This method is used to get the absolute value of the pixel-by-pixel difference between the two images.
Syntax: ImageChops.difference(image1, image2)
Parameters:
image1 first image
image2 second imageReturn Value: It returns an Image.
# This will import Image and ImageChops modulesfrom PIL import Image, ImageChops # Opening Imagesim = Image.open(r"C:\Users\Admin\Pictures\download.png")im2 = Image.open(r"C:\Users\Admin\Pictures\images.PNG") # here getting absolute difference# of image1 and image2im3 = ImageChops.difference(im, im2) # showing resultant imageim3.show() |
Output:
Images Used:


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course


