Skip to content
Related Articles

Related Articles

Python PIL | ImageChops.add_modulo() and ImageChops.difference() method

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 27 Jun, 2019

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 image

Return Value: It returns an Image.

Note: Both the images should be of same MODE.




# This will import Image and ImageChops modules
from PIL import Image, ImageChops
  
# Opening Images
im = Image.open(r"C:\Users\Admin\Pictures\download.png")
im2 = Image.open(r"C:\Users\Admin\Pictures\images.PNG")
  
# here adding image1 and image2
im3 = ImageChops.add_modulo(im, im2)
  
# showing resultant image
im3.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 image

Return Value: It returns an Image.




# This will import Image and ImageChops modules
from PIL import Image, ImageChops
  
# Opening Images
im = 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 image2
im3 = ImageChops.difference(im, im2)
  
# showing resultant image
im3.show()

Output:

Images Used:


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!