2

I have a tiff image stack in uint16 datatype and I’d like to convert this to uint8 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 in Fiji or alternatively in Python/MATLAB will be really helpful.

Natasha
  • 1,111
  • 5
  • 28
  • 66

1 Answers1

1

The im2uint8() function can be used to convert the image from uint16 (unsigned integer 16) to uint8 (unsigned integer 8) in MATLAB.

For .tiff Files with a Single Image :

Image = imread("Test_Image.tiff");
Image = im2uint8(Image);
imshow(Image);

For .tiff Files with Multiple Images and Saving Transformed/Converted Images:

Reading the images in a loop using the imread() function with second argument being the Image_Index corresponding to the image number within the .tiff image collection can be used to grab the entire image data stored in the file. Using imwrite() in append and WriteMode will allow each converted image to be saved into one file named in this example as Converted_Image.tiff.

%Multiple image tiff conversion%

File_Name = "Test_Image.tiff";
Image_Data = imfinfo(File_Name);
Number_Of_Images = length(Image_Data);


Tiff_Structure = struct('Image_File',[]);  

for Image_Index = 1: Number_Of_Images
    
      Image = imread(File_Name,Image_Index);
      Uint8_Image = im2uint8(Image);

      %For more information and plotting individual images%
      Tiff_Structure(Image_Index).Image_File = Uint8_Image;
      
      %Saving the converted images to one tiff file%
      imwrite(Uint8_Image,'Converted_Image.tiff','WriteMode','append');

end

Using MATLAB version: R2019b

MichaelTr7
  • 4,737
  • 2
  • 6
  • 21
  • Please find the image stack [here](https://ndownloader.figshare.com/files/21659829?private_link=5091cb1b57c1e7cfa112). I tried the above and I could successfully view the converted image via imshow. But I see only the first image in the stack. Could you please have a look at the input image? I would also like to know how to save the stack after conversion. – Natasha Oct 07 '20 at 06:23
  • @Natasha I edited the answer hopefully this suffices. – MichaelTr7 Oct 07 '20 at 07:08
  • Could you please suggest how to plot the histogram(like [this](https://github.com/DeepaMahm/misc/blob/master/6074129eead9d8669f91b6323311b7f8fa0f442c.png)) of the `Image_Data` in MATLAB? I looked at imhist but I think it for a single image. I am not sure how to use this for multiple images in the stack. I'd also like to rescale the data before converting data types. Since in 16 bits it is occupying only a small amount of the available value range. Kindly let me know if I have to post this question in a new thread. – Natasha Oct 14 '20 at 06:05
  • I'd say using `imhist()` on `Uint8_Image` within the loop would provide you with the histograms for each image within the stack. Also plotting multiple histograms/images can be done using `montage()` or `subplot()`. – MichaelTr7 Oct 15 '20 at 01:15
  • The rescaling and exact plotting details may be best suited for a new question. – MichaelTr7 Oct 15 '20 at 01:16
  • Sure. Could you please check this [post](https://stackoverflow.com/questions/64438731/how-to-rescale-image-data-before-converting-data-types)? – Natasha Oct 20 '20 at 05:04
  • 1
    Yeah, for sure. Will check it out soon. :) – MichaelTr7 Oct 20 '20 at 06:19