Converting an image from colour to grayscale using OpenCV


In this program, we will change the color scheme of an image from rgb to grayscale

Algorithm

Step 1: Import OpenCV.
Step 2: Read the original image using imread().
Step 3: Convert to grayscale using cv2.cvtcolor() function.

Example Code

import cv2
image = cv2.imread('colourful.jpg')
cv2.imshow('Original',image)
grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow('Grayscale', grayscale)

Output

Original Image:

Grayscale Image:

Updated on: 17-Mar-2021

14K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements