Splitting and Merging Channels with Python-OpenCV
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.
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])
- m: Input multi-channel array
- mv: Output vector of arrays
cv2.merge() is used to merge several single-channel images into a colored/multi-channel image.
Syntax: cv2.merge(mv[, dst])
- mv: Input vector of matrices to be merged. All matrices must have same size.
- dst: Output multi-channel array of size mv. Number of channel will be equal to total no. of channel in matrix array.