Thursday, July 4, 2024
HomeLanguagesPythonPython PIL | ImageChops.subtract() method

Python PIL | ImageChops.subtract() method

PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageChops module contains a number of arithmetical image operations, called channel operations (“chops”). These can be used for various purposes, including special effects, image compositions, algorithmic painting, and more.

PIL.ImageChops.subtract() 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. At least one of the images must have mode “1”.

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

Parameters:
image1: first image
image2: second image
scale: numeric value
offset: numeric value

Return Type: Image

Image1:

Image2:




# Importing Image and ImageChops module from PIL package  
from PIL import Image, ImageChops 
    
# creating a image1 object 
im1 = Image.open(r"C:\Users\sadow984\Desktop\a2.PNG"
    
# creating a image2 object 
im2 = Image.open(r"C:\Users\sadow984\Desktop\x5.PNG"
    
# applying subtract method 
im3 = ImageChops.add(im1, im2, scale = 1.0, offset = 2
    
im3.show() 


Output:




# Importing Image and ImageChops module from PIL package  
from PIL import Image, ImageChops 
    
# creating a image1 object 
im1 = Image.open(r"C:\Users\sadow984\Desktop\a2.PNG"
    
# creating a image2 object 
im2 = Image.open(r"C:\Users\sadow984\Desktop\x5.PNG"
    
# applying subtract method 
im3 = ImageChops.add(im1, im2, scale = 1.0, offset = 2
    
im3.show() 


Output:

Shaida Kate Naidoo
am passionate about learning the latest technologies available to developers in either a Front End or Back End capacity. I enjoy creating applications that are well designed and responsive, in addition to being user friendly. I thrive in fast paced environments. With a diverse educational and work experience background, I excel at collaborating with teams both local and international. A versatile developer with interests in Software Development and Software Engineering. I consider myself to be adaptable and a self motivated learner. I am interested in new programming technologies, and continuous self improvement.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments