Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

maybe like this:

// 1. convert to CV_16U
Mat u16; 
bgr.convertTo(u16, CV_16U); // no scaling factor, keep values "as is" !

// 2. split it (and throw away channel 0):
Mat chan[3];
split(16u, chan);

// 3. join green & red channel. 
// now you need to decide, which channel should be the "high", 
//   and which should be the "low" nibble of your 16bit img
//   we cannot simply "shift" Mat's so multiply by 256 instead:

Mat res = chan[1] + chan[2]*256; // M = G | (R<<8)

maybe like this:

// 1. convert to CV_16U
Mat u16; 
bgr.convertTo(u16, CV_16U); // no scaling factor, keep values "as is" !

// 2. split it (and throw away channel 0):
Mat chan[3];
split(16u, chan);

// 3. join green & red channel. 
// now you need to decide, which channel should one of them will be the "high", 
//   and which should be "high" 8bit nibble in a 16 bit value, the other the "low" nibble of your 16bit img
nibble.
//   we cannot simply "shift" Mat's so multiply by 256 instead:

Mat res = chan[1] + chan[2]*256; // M = G | (R<<8)