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 image

Return Value: It returns an Image.

Note: Both the images should be of same MODE.

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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()

chevron_right


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.

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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()

chevron_right


Output:

Images Used:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.