Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can do this operation "manually" (not using OpenCV funcions). You need a table corresponding an RGB color for each of the 65535 gray levels from the 16 bit image:

Scalar lut_table[65536];
// each value of the table is an RGB tuple

//...now initialize the lut_table variable with the LUT values you want...

//Applying the LUT table to the image
Mat dst(src.rows,src.cols,CV_8UC3)
for(int y=0;y<src.rows;y++)
    for(int x=0;x<src.cols;x++)
        dst.at<Scalar>(y,x)=lut_table[src.at<uint16_t>(y,x)];

The code should work, but I didn't test it, so it might contain errors.

You have to write your own generator for the LUT table (line 3 of the code). For example the following code generates a 8 bit grayscale LUT:

for(int i=0;i<65536;i++)
    lut_table[i]=Scalar(i/256,i/256,i/256);