1import cv2
2
3#Reading images in color and grayscale
4color_img = cv2.imread('cat.jpeg')
5gray_img = cv2.imread('cat.jpeg',0)
6
7#Displaying the image
8cv2.imshow('Cat image', color_img)
9
10#Storing the key pressed by user
11k = cv2.waitKey(0)
12
13#Check if user hits ‘c’ or ‘g’ key
14if( k == ord('c') ):
15 cv2.imwrite('color.jpg', color_img )
16 print("Image is saved color")
17 cv2.destroyAllWindows()
18
19if( k == ord('g') ):
20 cv2.imwrite('gray.jpg', gray_img )
21 print("Image saved in grayscale")
22 cv2.destroyAllWindows()