transform 16bit grayscale to RGB with constants
Hi,
I'm trying to figure out the most appropriate way to do this in OpenCV but I don't have much experience with it and feel like there should be a better way than just brute force.
I'm staring with a 16bit grayscale image (CV_16UC1) and I want to produce a RGB image (CV_8UC3)
But I don't want to use a simple conversion like o1.convertTo(o2, CV_8UC3, 1/255.0);
Rather, I have 3 constant scaling factors (each between 0 and 1 corresponding to each of R,G and B) Each resulting RGB pixel value should be the original 16bit grayscale pixel value multiplied by one of the three constants and then scaled down to a value between 0-255.
Thoughts? Thanks!
For that you will have to loop over image pixels, apply your manual conversion rule and push back the result in the correct matrix. Also how is your 16 single channel image containing 3 channel color information? o_o
so "brute force" (ie. looping through each pixel) is the way? (there's no "matrix" style multiplication I can do directly?)
to your question, the 16 single channel image does not contain color information, only grayscale pixel intensities. I am working on a "false coloring" so to speak. I have 3 constant values (all between 0-1) one for each of R, G and B, which when multiplied by the original grayscale value and scaled to 0-255, becomes the R, G and B values.
Well could you describe how your R G and B pixels are allocated inside the 16bit data? Then we might be able to figure out a smarter way.
The 16bit data is a purely grayscale image. I'm really just doing a "false coloring" by generating RGB values.
I've written this (simplified for space) which I think should get me there.
Each of those CONST values are scaling factors (between 0 and 1)
Ok it is false coloring but at the end I think you will have an image with only 256 differents colors?
in opencv there is no function to transform a basic 8 bits image in color
Thank you both for responses!