Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to each separate channel in OpenCV

Tags:

c++

opencv

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?

like image 511
iampat Avatar asked Jul 14 '11 20:07

iampat


People also ask

How do I split an image in 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.

What is Channel in OpenCV?

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.


1 Answers

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]; 
like image 81
orielfrigo Avatar answered Sep 23 '22 00:09

orielfrigo