Python Remove Green Channel from Color Image

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

Python Program

import cv2
import numpy as np

#read image
src = cv2.imread('D:/original.png', cv2.IMREAD_UNCHANGED)

# assign green channel to zeros
src[:,:,1] = np.zeros([src.shape[0], src.shape[1]])

#save image

Output Image

Python OpenCV - Remove Green Channel from Image

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.