Python PIL | ImageOps.colorize() Method
Last Updated :
26 Aug, 2019
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image
module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images.
PIL.ImageOps.colorize()
Colorize grayscale image. The black and white arguments should be RGB tuples; this function calculates a color wedge mapping all black pixels in the source image to the first color, and all white pixels to the second color.
Syntax: PIL.ImageOps.colorize(image, black, white)
Parameters:
image – The image to colorize.
black – The color to use for black input pixels.
white – The color to use for white input pixels.
Returns: An Image .
Image Used:
Code :
from PIL import Image, ImageOps
img = Image. open (r "C:\Users\System-Pc\Desktop\pinktree.jpg" ).convert( "L" )
img1 = ImageOps.colorize(img, black = "blue" , white = "white" )
img1.show()
|
Output:
Another Example: Here we use different parameters.
Image Used:
Code :
from PIL import Image, ImageOps
img = Image. open (r "C:\Users\System-Pc\Desktop\bird.jpg" ).convert( "L" )
img1 = ImageOps.colorize(img, black = "red" , white = "yellow" )
img1.show()
|
Output:
Share your thoughts in the comments
Please Login to comment...