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