1import cv2
2
3image = cv2.imread('C:/Users/N/Desktop/Test.jpg')
4gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
5
6cv2.imshow('Original image',image)
7cv2.imshow('Gray image', gray)
8
9cv2.waitKey(0)
10cv2.destroyAllWindows()
11
1import cv2
2
3# Reading color image as grayscale
4gray = cv2.imread("color-img.png",0)
5
6# Showing grayscale image
7cv2.imshow("Grayscale Image", gray)
8
9# waiting for key event
10cv2.waitKey(0)
11
12# destroying all windows
13cv2.destroyAllWindows()
1from PIL import Image
2img = Image.open('image.png').convert('LA')
3img.save('greyscale.png')