Python PIL | ImageChops.subtract() and ImageChops.subtract_modulo() method

PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities.

ImageChops.subtract() method –

This method subtracts two images, dividing the result by scale and adding the offset. If omitted, scale defaults to 1.0, and offset to 0.0.

Syntax: ImageChops.subtract(image1, image2, scale = 1.0, offset = 0)



Parameters:
image1: first image
image2: second image
scale: it is floating point value (if the value keeps on increasing, resultant image becomes darker and darker)
offset: numeric value (if value keeps on increasing, resultant image becomes lighter)

Return Value: 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\images.png")
im2 = Image.open(r"C:\Users\Admin\Pictures\download.PNG")
  
# subtracting im and im2
im3 = ImageChops.subtract(image1 = im, image2 = im2)
  
# showing resultant image
im3.show()

chevron_right


Output:

ImageChops.subtract_modulo() method –

This method is also used to subtract two images but without clipping the result.

Syntax: ImageChops.subtract_modulo(image1, image2)

Parameters: This method takes two images as parameters.

Return Value: 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\images.png")
im2 = Image.open(r"C:\Users\Admin\Pictures\download.PNG")
  
# subtracting im and im2
im3 = ImageChops.subtract_modulo(image1 = im, image2 = im2)
  
# showing resultant image
im3.show()

chevron_right


Output:



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.