Python PIL ImageOps.grayscale() method
Python PIL ImageOps.grayscale() Method
PIL is the Python Imaging Library, which provides image editing capabilities to the Python interpreter. The ImageOps module contains some “ready-to-use” image processing operations. This module is somewhat experimental, and most operations only work on RGB and LSI images.
ImageOps.grayscale() Converts an image to grayscale. Entire pixels are rendered gray, and no other colors are visible.
Syntax: PIL.ImageOps.grayscale(image)
Parameters:
image – The image to be converted to grayscale.
Return an image.
Images used:
# Importing Image and ImageOps module from PIL package
from PIL import Image, ImageOps
#creating a image1 object
im1 = Image.open(r"C:UsersSystem-PcDesktopa.JPG")
# applying grayscale method
im2 = ImageOps.grayscale(im1)
im2.show()
Output: