Python PIL | logical_xor() and invert() method
PIL.ImageChops.logical_xor() method applies Logical XOR between two images. At least one of the images must have mode “1”.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
Image 1:
Image2:
Syntax: PIL.ImageChops.logical_xor(image1, image2)
Parameters:
image1: first image
image2: second imageReturn 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_xor method im3 = ImageChops.logical_xor(im1, im2) im3.show() |
Output:
PIL.ImageChops.invert() method invert an image (channel).
Syntax: PIL.ImageChops.invert(image)
Parameters:
image1: imageReturn 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") # applying invert method im3 = ImageChops.invert(im1) im3.show() |
Output:


