Read shape of image
image:np.ndarray = cv2.imread("cow.jpg") print(image.shape)
Output
(559, 838, 3)
Show one channel
image: np.ndarray = cv2.imread("cow.jpg") # channels : BGR => 0,1,2 image2 = image[:, :, 1] # show channel 1 which is Green cv2.imshow("image", image2) cv2.waitKey(0) cv2.destroyAllWindows()
Manipulate channel
image: np.ndarray = cv2.imread("cow.jpg") image2 = image.copy() # channels : BGR => 0,1,2 # Here we want to show only Red channel image2[:, :, 0] = 0 image2[:, :, 1] = 0 cv2.imshow("image", image2) cv2.waitKey(0) cv2.destroyAllWindows()