Skip to main content

Display image in Gray Scale Python

Gray Scale Image Python:
                        Python have option to convert image to Gray. The following code convert normal image to gray scale.

import cv2 
# Read the main image 
img_rgb = cv2.imread('mahindra.png')
# Convert it to grayscale 
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) 

  • The package cv2 is used to read image from file.  img_rgb = cv2.imread('mahindra.png').
  • cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)  will convert rgb image to gray scale image.
  • cv2.imshow('Detected',img_gray)  will display image.