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.
Image.convert() Returns a converted copy of this image. For the âPâ mode, this method translates pixels through the palette. If mode is omitted, a mode is chosen so that all information in the image and the palette can be represented without a palette.
Syntax: Image.convert(mode=None, matrix=None, dither=None, palette=0, colors=256)
Parameters:
mode â The requested mode. See: Modes.
matrix â An optional conversion matrix. If given, this should be 4- or 12-tuple containing floating point values.
dither â Dithering method, used when converting from mode âRGBâ to âPâ or from âRGBâ or âLâ to â1â. Available methods are NONE or FLOYDSTEINBERG (default).
palette â Palette to use when converting from mode âRGBâ to âPâ. Available palettes are WEB or ADAPTIVE.
colors â Number of colors to use for the ADAPTIVE palette. Defaults to 256.
Returns: An Image object.
Image Used:

from PIL import Image
img = Image.open(r"C:\Users\System-Pc\Desktop\scene3.jpg")
img1 = img.convert("L")
img1.show()
img2 = img.convert("1")
img2.show()
|
Output1:

Output2:

Another Example: Taking another image.
Image Used:
from PIL import Image
img = Image.open(r"C:\Users\System-Pc\Desktop\scene4.jpg")
img1 = img.convert("L")
img1.show()
img2 = img.convert("1")
img2.show()
|
Output1:

Output2:

Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.Dive into the future of technology - explore the
Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.
Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated :
26 Jul, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...