Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 365
tidy Avatar asked Dec 12 '22 03:12

tidy


2 Answers

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().

like image 117
bikz05 Avatar answered Jan 26 '23 00:01

bikz05


Keep things simple and use extractChannel, which wraps mixChannels for you.

cv::Mat hue;
int cn = 0; // hue
cv::extractChannel(hsv, hue, cn);
like image 45
chappjc Avatar answered Jan 25 '23 23:01

chappjc