I am newbie in openCV
and trying to convert the image of 16 bit
grayscale
image to a color image using color palatte. I have done this operation when I have 8 bit
image but now I am fetching the image frame from the thermal camera which give me 16 bit frame and I can't convert that to 8 bit
because it decreases the quality of the image which is useless. In 8 bit
image I have use LUT
function for doing this task.
My Lookup table Code for 8 bit image
Mat palette, im;
palette = imread("1.bmp", IMREAD_COLOR);
im = imread("C:\\Users\\Chandrapal Singh\\Desktop\\New folder\\IMG_0_10_34_45_2018_1.bmp", IMREAD_GRAYSCALE);
im.convertTo(im, CV_16U);
cvtColor(im.clone(), im, COLOR_GRAY2BGR);
double scale = (double)palette.rows / 256;
uchar b[256], g[256], r[256];
int i = 0;
for (double x = 1; x <= palette.rows;) {
b[i] = palette.at<Vec3b>((int)x, palette.cols / 2)[0];
g[i] = palette.at<Vec3b>((int)x, palette.cols / 2)[1];
r[i] = palette.at<Vec3b>((int)x, palette.cols / 2)[2];
i++;
x += scale;
}
Mat channels[] = { Mat(256,1, CV_8U, b), Mat(256,1, CV_8U, g), Mat(256,1, CV_8U, r) };
Mat lut;
cv::merge(channels, 3, lut);
Mat color;
cv::LUT(im, lut, color);
In above code palette
is a color palatte and im
is a grayscale image. I am reading the color of palette and put that in lut
and then using LUT
function just making a colored image.
So, can anyone help me how I can do the above with 16 bit image. Thanks in Advance.
When I run this code I got execption which says:-
I am getting a exception which says Assertion failed ((lutcn == cn || lutcn == 1) && _lut.total() == 256 && _lut.isContinuous() && (depth == 0 || depth == 1)) in cv:: LUT