Search code examples
opencvimage-processingmathsv

opencv split vs mixChannels


To separate hue channel from HSV image, here is the code using the mixChannels function:

/// Transform it to HSV
cvtColor( src, hsv, CV_BGR2HSV );

/// Use only the Hue value
hue.create( hsv.size(), hsv.depth() );
int ch[] = { 0, 0 };
mixChannels( &hsv, 1, &hue, 1, ch, 1 );

But I know split function can also do this:

vector<Mat> chs;
split(hsv, chs);
Mat hue = chs[0];

Is that OK? If these are the same, I think split method is more clean. Am I right?


Solution

  • You are pretty much right, split() is used to split all the channels of an multi-channel matrix into single channel matrices. On the other hand if you are interested in only one channel you can use mixChannels(). So you don't have to allocate memory for other channels as we do with split().