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
from PIL import Image, ImageChops
im = Image. open (r "C:\Users\Admin\Pictures\images.png" )
im2 = Image. open (r "C:\Users\Admin\Pictures\download.PNG" )
im3 = ImageChops.subtract(image1 = im, image2 = im2)
im3.show()
|
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.
from PIL import Image, ImageChops
im = Image. open (r "C:\Users\Admin\Pictures\images.png" )
im2 = Image. open (r "C:\Users\Admin\Pictures\download.PNG" )
im3 = ImageChops.subtract_modulo(image1 = im, image2 = im2)
im3.show()
|
Output:
Last Updated :
27 Jun, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...