Opening multileveled TIFF images in Matlab

 The issue: this is a simple issue. I generally open single-leveled TIFF files in Matlab by simply using the function:

  data = imread('example.tif');

However, if the tif file in question is multi-layered (3D), this command will only open the top layer and ignore the rest. 


Solution: There are two possible solutions for this problem.

1. Using only one command (tested in MatLab R2023, documentation refers to being first released with R2020b):

     data  = tiffreadVolume('example.tif');

The numerical array data will therefore have 3 dimensions (x,y,z). I got it automatically in the format uint8 when I tried. Between the two solutions, this one is the fastest.


2. Using multiple lines (maybe for versions prior to MatLab R2020b): 

    info = imfinfo('example.tif');

  data = zeros(info(1).Width,info(1).Height,numel(info)); %preallocates the data array.

  data = uint8(data); %converts the array from double to uint8 (or uint16, if chosen).

  for i = 1:numel(info)

    data(:,:,i) = imread('example.tif',i);

  end

You get the same result as method 1. The variable info will be a structure with the same number of elements as the number of layers present in the tif file. 



Kommentarer

Populære innlegg fra denne bloggen

Opening Zeiss czi file format mosaic files in Matlab using bio-formats

Possible solution for problems opening confocal files from Zeiss LSM 880 in Neurolucida 360 environment