Skip to content

Instantly share code, notes, and snippets.

@StevenPuttemans
Last active March 24, 2017 14:11
Show Gist options
  • Save StevenPuttemans/f672274f0868c8dc1885 to your computer and use it in GitHub Desktop.
Save StevenPuttemans/f672274f0868c8dc1885 to your computer and use it in GitHub Desktop.
[OPENCV3.2] Efficiently merge single channels into multi channel matrix
// Approach 1
Mat result_channel(rows, cols, CV_8UC3);
Mat in[] = { blue_channel, green_channel, red_channel };
int from_to[] = { 0,0, 1,1, 2,2 };
mixChannels( in, 3, &result_channel, 1, from_to, 3 );
// Approach 2
blue_channel.copyTo( result_channel( Rect(0, 0, cols, rows) ) );
green_channel.copyTo( result_channel( Rect(cols, 0, cols, rows) ) );
red_channel.copyTo( result_channel( Rect(cols*2, 0, cols, rows) ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment