Converting a 12-bit grayscale image to 8-bit per channel color image in Python
My first question would be: Why do you need to convert it to color in any specific way?
If you are training the CNN on these images, any arbitrary transformation should work and give you similar performance. You just need to convert the training images and input images in the same manner.
You could probably just split the 16 bits and put the bottom half in R, the top half in G, and leave B with zeroes.
It kinda depends on how black-box this CNN is. But you can always test this by running a few training/testing cycles with the conversion I mentioned above and then do that again with the "compressed" versions.
I am looking for suggestions or best practices to follow in terms of converting a 12-bit (0-4096) grayscale image to a 3-channel 8-bit color image in Python in order to pass it into a convolutional neural network.
With 8-bit RGB, I essentially have 24-bit colour, so I see no reason to lose data in the conversion, although most other posts suggest simply dividing the pixel value by 16 in order to squeeze it into 8-bits and then replicating this over all three channels in a lossy way.
Some ideas I have come up with include creating some kind of gradient function that converts the 12-bit uint to a corresponding colour on the gradient, but my understanding of the RGB colour space is that this would be tricky to implement using Numpy or other such libraries.
Do any of the common libraries such as OpenCV / Scikit offer this kind of functionality?  I cannot find anything in the docs.  Other ideas include using some kind of intermediary color space such as HSL/L*AB but I don't really know enough about this.
Please note that I am ultimately trying to create an 8-bit RGB image, not a 16-bit RGB image.  Simply trying to colorize the grayscale image in a way that retains the original 12-bit data across the colour range.
Hope somebody can help!