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: