Python PIL | ImageChops.constant ()

Python Methods and Functions

PIL — is a Python image library that provides the Python interpreter with image editing capabilities. The Image module provides a class with the same name that is used to represent a PIL image. The module also provides a number of factory functions, including the functions of loading images from files and creating new images.

PIL.ImageChops.constant() Fill the channel the specified gray level.

Syntax: PIL.ImageChops.constant (image, value)

Parameters:
image - take an image with there extension type.

Returns: An Image.

Image used:

  

  
# import image object from PIL

from PIL import  Image, ImageChops 

 
# create an image object

img = Image. open (r " C: UsersSystem-PcDesktopTREE.JPG "

img1 = ImageChops.constant ( img, 60

 
img1.show () 

Output:

Another example: Create another image with a different value to see the change in gray intensity.

Image used:

 

 
# import image object from PIL

from PIL import Image, ImageChops 

 
# create an image object

img = Image. open (r "C: UsersSystem-PcDesktop ose.jpg"

img1 = ImageChops.constant (img, 200

 
img1.show () 

Output: