Splitting and Merging Channels with Python-OpenCV Last Updated : 03 Jan, 2023 Comments Improve Suggest changes Like Article Like Report In this article, we will learn how to split a multi-channel image into separate channels and combine those separate channels into a multi-channel image using OpenCV in Python. To do this, we use cv2.split() and cv2.merge() functions respectively. Image Used: Splitting Channels cv2.split() is used to split coloured/multi-channel image into separate single-channel images. The cv2.split() is an expensive operation in terms of performance(time). The order of the output vector of arrays depends on the order of channels of the input image. Syntax: cv2.split(m[, mv]) Parameters: m: Input multi-channel arraymv: Output vector of arrays Example: Python3 # Python program to explain splitting of channels # Importing cv2 import cv2 # Reading the image using imread() function image = cv2.imread('img.jpg') # Displaying the original BGR image cv2.imshow('Original_Image', image) # Using cv2.split() to split channels of coloured image b,g,r = cv2.split(image) # Displaying Blue channel image # Blue colour is highlighted the most cv2.imshow("Model Blue Image", b) # Displaying Green channel image # Green colour is highlighted the most cv2.imshow("Model Green Image", g) # Displaying Red channel image # Red colour is highlighted the most cv2.imshow("Model Red Image", r) # Waits for user to press any key cv2.waitKey(0) Output: Merging Channels cv2.merge() is used to merge several single-channel images into a colored/multi-channel image. Syntax: cv2.merge(mv[, dst]) Parameters: mv: Input vector of matrices to be merged. All matrices must have same size.dst: Output multi-channel array of size mv[0]. Number of channel will be equal to total no. of channel in matrix array. Example: Python3 # Python program to explain Merging of Channels # Importing cv2 import cv2 # Reading the BGR image using imread() function image = cv2.imread("img.jpg") # Splitting the channels first to generate different # single # channels for merging as we don't have separate # channel images b, g, r = cv2.split(image) # Displaying Blue channel image cv2.imshow("Model Blue Image", b) # Displaying Green channel image cv2.imshow("Model Green Image", g) # Displaying Red channel image cv2.imshow("Model Red Image", r) # Using cv2.merge() to merge Red, Green, Blue Channels # into a coloured/multi-channeled image image_merge = cv2.merge([r, g, b]) # Displaying Merged RGB image cv2.imshow("RGB_Image", image_merge) # Waits for user to press any key cv2.waitKey(0) Output: Comment More infoAdvertise with us Next Article Splitting and Merging Channels with Python-OpenCV vibhutijain99 Follow Improve Article Tags : Python OpenCV Python-OpenCV Practice Tags : python Similar Reads Histogram matching with OpenCV, scikit-image, and Python Histogram matching is used for normalizing the representation of images, it can be used for feature matching, especially when the pictures are from diverse sources or under varied conditions (depending on the light, etc). each image has a number of channels, each channel is matched individually. His 3 min read Convert BGR and RGB with Python - OpenCV Prerequisites: OpenCV OpenCV is a huge open-source library for computer vision, machine learning, and image processing. OpenCV supports a wide variety of programming languages like Python, C++, Java, etc. It can process images and videos to identify objects, faces, or even the handwriting of a human 2 min read Python OpenCV - Getting and Setting Pixels In this article, we will discuss Getting and Setting Pixels through OpenCV in Python. Image is made up of pixels. A pixel will be denoted as an array. The 3 integers represent the intensity of red, green, blue in the same order. Eg. [0,0,0] in RGB mode represent black color. There are other modes a 3 min read Getting Started with Python OpenCV Computer Vision is one of the techniques from which we can understand images and videos and can extract information from them. It is a subset of artificial intelligence that collects information from digital images or videos. Python OpenCV is the most popular computer vision library. By using it, o 15+ min read Concatenate images using OpenCV in Python To concatenate images vertically and horizontally with Python, cv2 library comes with two functions as: hconcat(): It is used as cv2.hconcat() to concatenate images horizontally. Here h means horizontal.vconcat(): It is used as cv2.vconcat() to concatenate images vertically. Here v means vertical.Im 3 min read Reading an image in OpenCV using Python Prerequisite: Basics of OpenCVIn this article, we'll try to open an image by using OpenCV (Open Source Computer Vision) library.  Following types of files are supported in OpenCV library:Windows bitmaps - *.bmp, *.dibJPEG files - *.jpeg, *.jpgPortable Network Graphics - *.png WebP - *.webp Sun raste 6 min read Erosion and Dilation of images using OpenCV in python Morphological operations are a set of operations that process images based on shapes. They apply a structuring element to an input image and generate an output image. The most basic morphological operations are two: Erosion and Dilation Basics of Erosion: Erodes away the boundaries of the foreground 2 min read Python OpenCV - startWindowThread() Function This article will discuss how to use the python OpenCV startWindowThread() function. Do you want to display images and videos using a simplified interface through an OpenCV code? Then, you must check out the OpenCV startWindowsThread() function, which lets you use the high GUI windows, i.e., a simpl 3 min read Automatic color correction with OpenCV and Python Colour correction is an important aspect of image processing and is used to correct any colour imbalances in an image. OpenCV is an open-source library for computer vision and image processing tasks that provides several functions and tools to analyze and manipulate images. In this tutorial, we will 3 min read How to Display an OpenCV image in Python with Matplotlib? The OpenCV module is an open-source computer vision and machine learning software library. It is a huge open-source library for computer vision, machine learning, and image processing. OpenCV supports a wide variety of programming languages like Python, C++, Java, etc. It can process images and vide 2 min read Like