1 | initial version |
If I understand correctly, you have an image with 16 bit pixel values and you want to convert to 8 bit and back without losing precision. You cannot do this, as in converting to 8 bits you are throwing away 8 bits worth of data. Depending on the value of maxval some of them would be expected to hold some information.
Let me demonstrate:
Say the first 3 pixels in an image have values of 256,257 and 258 and maxval is 1020. The corresponding three pixels in the 8 bit image would be 64,64 and 64... Converting back to 16 bits you would get 256, 256 and 256.
You could overcome this problem by keeping a second image with the "remainders" and then adding it to the new 16 bit image.
guy