Ask Your Question

Converting 16UC1 to 8UC3 without the loss of the data

asked 2017-11-04 14:23:23 -0500

sjhalayka gravatar image

updated 2017-11-04 14:27:12 -0500

I'm trying to convert a 16UC1 mat to an 8UC3 mat, somehow without truncating the data. Do you have a preferred method? The code I'm trying splits the one 16-bit value into two 8-bit values, which I use for the blue and green channels.

UINT16 a =<UINT16>(j, i);
BYTE hi = (a >> 8) & 0xff;
BYTE low = (a >> 0) & 0xff;<Vec3b>(j, i)[0] = hi; // blue<Vec3b>(j, i)[1] = low; // green<Vec3b>(j, i)[2] = 0; // red
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-11-04 14:48:23 -0500

Tetragramm gravatar image

If you simply want to store the 16 bit values into a 8 bit, 3 channel image, that's fine. Your method allows you to extract subwindows and things like that. If you don't care about that, then it's probably better just to copy it to the memory block, leaving the rest empty.

However, obviously, neither of these looks like an image if you display or process the data.

If you want it to still be an image, and you simply want to lose as little visual fidelity as possible, then you should look for Contrast Enhancement and Local Area Contrast Enhancement methods, such as Histogram Equalization, CLAHE, or one of the many many other methods that do LACE.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-11-04 14:23:23 -0500

Seen: 168 times

Last updated: Nov 04 '17