Open In App

Python PIL | logical_and() and logical_or() method

Improve
Improve
Like Article
Like
Save
Share
Report
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.logical_and() method applies Logical AND between two images. At least one of the images must have mode “1”.

Image 1:

Image2:

Syntax: PIL.ImageChops.logical_and(image1, image2)

Parameters: 
image1: first image
image2: second image

Return Type: Image




# 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") .convert("1")
    
# creating a image2 object 
im2 = Image.open(r"C:\Users\sadow984\Desktop\x5.PNG") .convert("1")
    
# applying logical_and method 
im3 = ImageChops.logical_and(im1, im2) 
    
im3.show() 


Output:

PIL.ImageChops.logical_or() method applies Logical OR between two images. At least one of the images must have mode “1”.

Syntax: PIL.ImageChops.logical_or(image1, image2)

Parameters: 
image1: first image
image2: second image

Return Type: Image




# 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") .convert("1")
    
# creating a image2 object 
im2 = Image.open(r"C:\Users\sadow984\Desktop\x5.PNG") .convert("1")
    
# applying logical_or method 
im3 = ImageChops.logical_or(im1, im2) 
    
im3.show() 


Output:



Last Updated : 06 Nov, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads