I’ve created a small tool that generates a LUT and applies it to an image. The LUT is used to transform an m-bit image into an n-bit image. E.g. a 16-bit image into a 10-bit image, or an 8-bit image into a 12-bit image. For now these images are monochrome. The tool mostly works, except for the following:
The LUT.Apply method seems to return an image that has a data type of either 8-bit, or 16-bit, depending upon the input image data type: E.g. if I input a 10-bit image, it returns me a 16-bit image. If I input an 8-bit image, it returns me an 8-bit image. This causes me two issues.
I’d like to save the output image as an MIO file with the appropriate data type, at the moment, I’m stuck with 8-bit or 16-bit.
This also means I can’t transform an 8-bit image into a 10-bit image, because the LUT.Apply method only returns an 8-bit image if an 8-bit image is inputted.
I can resolve both of these issues if I can cast an image from one data type to another. E.g. I wish to be able to cast an 8-bit image to a 16-bit image without the pixel values changing. Likewise, I wish to cast a 16-bit image to a 10-bit image, but in this 16-bit image, there aren’t any pixel values above 10-bit, so no information should be lost from the cast.
Basically, the point of my question is; how can I cast an image from one data-type to another?
If my post was unclear, let me know and I can clarify.
EDIT: I should add, the LUT does not perform a simple linear conversion from m-bit to n-bit, so I can’t just multiply the values.