Convert image datatype from unit16 to unit8

Hello Everyone,
I have a tiff image stack in unit16 datatype and I’d like to convert this to unit8 datatype. I’m not sure how to do this in Fiji.

I have loaded the stack in Fiji and I tried to change the datatype while exporting. But I couldn’t find any tab in Fiji export options for specifying the datatype.

Suggestions on how to do this will be really helpful

Hi @Deepa,

the menu is Image > Type > 8-,bit. Please not that this conversion comes with information loss and depends on Brightness/contrast settings. So, just be a bit careful and better don’t measure intensity quantitatively in the resulting stack.

May I ask what’s the reason why you want to do this lossy conversion?


Hi @haesleinhuepf

Thank you. I tried the above after loading this input. Unfortunately, I see this error while exporting the converted file.

Sure, link

In which format are you exporting?

@haesleinhuepf I tried File > Export > Image > out.tif

So when I do this in my Fiji and record a macro, these three lines come up:

saveAs("Tiff", "C:/Users/rober/Downloads/m800-0-36X-1_iso_ch1-1.tif");

And it works. If this macro doesn’t work on your computer, I would wonder what’s different in your setup. To figure this out, would you mind trying a freshly downloaded Fiji?

1 Like

Thanks a lot! I will try this out

Hi @Deepa, @haesleinhuepf,

I’m writing after having looked at the data, and with a histogram like this:

you should probably rescale your data before converting data types. In 16 bits it is occupying only a small amount of the available value range (although the max is at 65535).

With the conversion as is, you are losing too much detail, which also results in bad segmentation results…

What would be the fiji way to do that?

1 Like

Hi @k-dominik In MATLAB, I could use im2uint8 to convert the datatype and the documentation mentions the following

J = im2uint8( I ) converts the grayscale, RGB, or binary image I to uint8 , rescaling or offsetting the data as necessary.

From what I understand, im2unit8 rescales the image data.
I’m also sharing the MATLAB code here for your kind reference.

Could you please elaborate a bit on this? I’m afraid I don’t completely understand how the data has to be rescaled. Should the rescaled values lie in a specific interval [a,b]?
I shall try this in MATLAB if that could help.