OpenCV – Remove Green Channel from Image
To remove red channel from color image, read image to BGR array using cv2.imread() and assign zeros to the 2D array corresponding to green channel.
In this tutorial, we shall use OpenCV Python library and transform an image, such that no green channel is present in the image.
Example 1: Remove Green Component from Image
In this example, we will remove the green channel from the following image.
Source or Input Image
import cv2 import numpy as np #read image src = cv2.imread('D:/original.png', cv2.IMREAD_UNCHANGED) print(src.shape) # assign green channel to zeros src[:,:,1] = np.zeros([src.shape, src.shape]) #save image cv2.imwrite('D:/no-green-channel.png',src)
This image has only red and blue channels of the original image.
In this tutorial of Python Examples, we learned how to extract green channel from an image.