Combining two 8 bit channels to one 16 bit channel consecutively

Dear all,

I am currently working with a thermal camera. The difference is, a “normal” camera has 3 pixels (RGB) with 8 bit each, while a thermal camera has only one pixel (greyscale) but with 14 bit. Since most imaging tools are designed for 24 bit (3x8 bit RGB), the software stores the data in one RGB image where the red channel is empty and green and blue share the information, which means, B contains the values 0-255 (8 Bit) and G the rest. I can open the RGB image in ImageJ and use Image -> Color -> Split Channels and I get all three channels separately, the R which is only black and the B and G with different values. Now I would like to add B and G consecutively in one 16 bit greyscale image; starting with B from 0-255 and G with 256-XXX.
Is there any way to tell ImageJ, that the layer B has the values 0-255 and G starts from 256? It is like a stacking, but instead of adding both channels in the same layer, the G has to be shifted by +8 bit (256).

So to clarify:
Starting image (3x8 bit):
R (no information)
G (256-XXX)
B (0-255)

What I would like to have (16 bit greyscale):
Grey (0-XXX)

Thank you very much for your help!

Greetings Sebastian

Hi Sebastian.
First, duplicate your green image and threshold it (1-255). It will later be used as a mask.
Then transform your green image in 16 bits (Image>Type) and then add 255 to it (Process>Math>Add). Then thanks to Process>Image calculator, multiply the mask and the green image (you then have values between 0 and 256 to XXX). You will then computed a maximum (with Process>Image calculator) between this result image and your blue image (becareful of the order or cast first your blue image in 16 bits).

Nico

Hi Nico,

thank you for your quick response! It works like a charm!

Greetings Sebastian

P.S.
Of course it is not that simple that you add two 8 Bit channels to a 16 Bit channel… they have to interlink…

Hi,

I think the right way to this is to multiply the green channel by 256 (rather than adding 255). This is equivalent to shifting the bits to the left which is what you need.

The steps would be

  • convert the green to 16bit
  • multiply by 256
  • add the red channel to the green
    (No mask needed)

Cheers,

Chris

Hi,
You’re true. It depends the way the bits are coded.
If values are just shifted (like I understood Sebastian said), my computation is ok.
But if bits are shifted, @evenhuis, your solution is right.

For example with B = 10 and G = 2 ;

  • in the first case, the final value is 267 (but the max value is 511; 2^9 values are coded with 9 bits)
  • in the second case, the final value is 522 (max value is 65536 ; values are coded with 16 bits).

Be careful @Seb1 ; are the values or the bits shifted ?

Nico

If they’re storing 14-bits it has to be shifted bits.

-Chris

1 Like

Dear all,
thank you very much for your effort! I will try your suggestions tomorrow!
Greetings Sebastian

Dear Chris,
your answer solved my problem, thank you very much!
Really nice image tool and a kind and helpful community!
Cheers Sebastian