How to split an image into different color channels in OpenCV Python?

A color image consists of three color channels Red, Green, and Blue. These color channels can be split using cv2.split() function in OpenCV Python. This technique is useful for analyzing individual color components or applying channel-specific processing.

Syntax

blue, green, red = cv2.split(image)

The cv2.split() function takes a BGR image as input and returns three separate arrays representing the Blue, Green, and Red channels respectively.

Steps to Split Color Channels

  • Import the required library. In all the following examples, the required Python library is OpenCV. Make sure you have already installed it.

  • Read the input image using cv2.imread() method. Specify full path of image with the image type (i.e. png or jpg).

  • Apply cv2.split() function on the input image. It returns blue, green and red channel pixel values as numpy arrays.

  • Display the channels as grayscale or color images as needed.

We will use this image as the Input File in the following examples

Example 1: Display Channels as Grayscale Images

In this example, we split an input image into its constituent color channels and display each channel as a grayscale image ?

# import required libraries
import cv2

# read the input color image
img = cv2.imread('bgr.png')

# split the Blue, Green and Red color channels
blue, green, red = cv2.split(img)

# display three channels as grayscale
cv2.imshow('Blue Channel', blue)
cv2.waitKey(0)
cv2.imshow('Green Channel', green)
cv2.waitKey(0)
cv2.imshow('Red Channel', red)
cv2.waitKey(0)
cv2.destroyAllWindows()

When you run the above Python program, it will produce the following three output windows, each showing a color channel (blue, green and red) as a grayscale image ?

Example 2: Display Channels in Color

In this example, we split an input image and display each channel in its respective color by merging it with zero arrays ?

# import required libraries
import cv2
import numpy as np

# read the input color image
img = cv2.imread('bgr.png')

# split the Blue, Green and Red color channels
blue, green, red = cv2.split(img)

# define channel having all zeros
zeros = np.zeros(blue.shape, np.uint8)

# merge zeros to make BGR image
blueBGR = cv2.merge([blue, zeros, zeros])
greenBGR = cv2.merge([zeros, green, zeros])
redBGR = cv2.merge([zeros, zeros, red])

# display the three Blue, Green, and Red channels as BGR image
cv2.imshow('Blue Channel', blueBGR)
cv2.waitKey(0)
cv2.imshow('Green Channel', greenBGR)
cv2.waitKey(0)
cv2.imshow('Red Channel', redBGR)
cv2.waitKey(0)
cv2.destroyAllWindows()

When you run the above Python program, it will produce the following three output windows each showing a color channel (blue, green and red) as a color image ?

Key Points

  • cv2.split() returns channels in BGR order (Blue, Green, Red), not RGB.

  • Each channel is returned as a 2D numpy array with the same height and width as the original image.

  • To display channels in color, merge them with zero arrays using cv2.merge().

  • Channel splitting is useful for color-based image analysis and processing.

Conclusion

OpenCV's cv2.split() function provides an efficient way to separate color channels from BGR images. You can display these channels as grayscale images for analysis or merge them with zero arrays to visualize individual color components.

Updated on: 2026-03-26T22:53:36+05:30

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements