I have an image with 3 channels (img) and another one with a single channel (ch1).
Mat img(5,5,CV_64FC3); Mat ch1 (5,5,CV_64FC1);
Is there any efficient way (not using for loop) to copy the first channel of img to ch1?
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.
There are three channels in an RGB image- red, green and blue. The color space where red, green and blue channels represent images is called RGB color space. In OpenCV, BGR sequence is used instead of RGB. This means the first channel is blue, the second channel is green, and the third channel is red.
In fact, if you just want to copy one of the channels or split the color image in 3 different channels, CvSplit()
is more appropriate (I mean simple to use).
Mat img(5,5,CV_64FC3); Mat ch1, ch2, ch3; // "channels" is a vector of 3 Mat arrays: vector<Mat> channels(3); // split img: split(img, channels); // get the channels (dont forget they follow BGR order in OpenCV) ch1 = channels[0]; ch2 = channels[1]; ch3 = channels[2];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With