Access to each separate channel in OpenCV

Viewed 76454

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?

5 Answers

You can access a specific channel, it works faster than the split operation

Mat img(5,5,CV_64FC3);
Mat ch1;
int channelIdx = 0;
extractChannel(img, ch1, channelIdx); // extract specific channel

// or extract them all
vector<Mat> channels(3);
split(img, channels);
cout << channels[0].size() << endl;
Related