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?
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()
.
Keep things simple and use extractChannel
, which wraps mixChannels
for you.
cv::Mat hue;
int cn = 0; // hue
cv::extractChannel(hsv, hue, cn);
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