Code covered by the BSD License  

Highlights from
Read TIFF stacks into Matlab fast, with lazy loading

5.0 | 1 rating Rate this file 50 Downloads (last 30 days) File Size: 15.2 KB File ID: #32025
image thumbnail

Read TIFF stacks into Matlab fast, with lazy loading


Dylan Muir (view profile)


01 Jul 2011 (Updated )

Read a TIFF stack as a memory-mapped tensor. Handles a large range of internal TIFF formats.

| Watch this File

File Information

See also
If this code is useful to your academic work, please cite the publication in lieu of thanks:
Muir and Kampa, "FocusStack and StimServer: A new open source MATLAB toolchain for visual stimulation and analysis of two-photon calcium neuronal imaging data". Frontiers in Neuroinformatics (accepted).
Usage: tsStack = TIFFStack(strFilename <, bInvert>)
A TIFFStack object behaves like a read-only memory mapped TIF file. The entire image stack is treated as a matlab tensor. Each frame of the file must have the same dimensions. Reading the image data is optimised to the extent possible; the header information is only read once.
This class attempts to use the version of tifflib built-in to recent versions of Matlab, if available. Otherwise this class uses a modified version of tiffread [1, 2] to read data. Code is included (but disabled) to use the matlab imread function, but imread returns invalid data for some TIFF formats.
permute, ipermute and transpose are now transparantly supported. Note that to read a pixel, the entire frame containing that pixel is read. So reading a Z-slice of the stack will read in the entire stack.
>> tsStack = TIFFStack('test.tiff'); % Construct a TIFF stack associated with a file
>> tsStack = TIFFStack('test.tiff', true); % Indicate that the image data should be inverted
tsStack =
  TIFFStack handle
         bInvert: 0
     strFilename: [1x9 char]
      sImageInfo: [5x1 struct]
    strDataClass: 'uint16'
>> tsStack(:, :, 3); % Retrieve the 3rd frame of the stack, all planes
>> tsStack(:, :, 1, 3); % Retrieve the 3rd plane of the 1st frame
>> size(tsStack) % Find the size of the stack (rows, cols, frames, planes per pixel)
ans =
   128 128 5 1

>> tsStack(4); % Linear indexing is supported
>> tsStack.bInvert = true; % Turn on data inversion

[1] Francois Nedelec, Thomas Surrey and A.C. Maggs. Physical Review Letters 86: 3192-3195; 2001. DOI: 10.1103/PhysRevLett.86.3192

Required Products MATLAB
MATLAB release MATLAB 7.11 (R2010b)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
09 Mar 2015 Dylan Muir

Dylan Muir (view profile)

Hi Jana, the class has documentation available if you type `help TIFFStack`. What seems to be the problem?

Comment only
09 Mar 2015 Jana Katharina Wrosch

Can't get this to work. Is there a documentation on how to use it?

Comment only
24 Jul 2011 Federico

Best way, to my knowledge, to work with TIFF stacks on Matlab. Recommended.

24 Jul 2011

Fixed a bug when indexing non-square TIFF files.

27 Jul 2011

Fixed a bug when referencing slice 58 of a stack.

16 Aug 2011

Updated screenshot

30 Sep 2011

Updated link to Francois Nedelec

07 Nov 2011

Updated description

05 Sep 2013

Dramatic acceleration by using tifflib when possible. Added support for permute and transpose.

05 Mar 2014

Updated description

26 Mar 2014

Updated description

17 Jun 2014

Updated description

23 Oct 2014

Fixed a bug in indexing into an image file

04 Nov 2014

Fixed bugs where tifflib would cause a crash when TIFFStack was not called with a valid filename.

09 Nov 2014

Fixed a bug where tiffflib would fail to read tiled images correctly.

08 Dec 2014

Added paper reference.

20 Jan 2015

Improved efficiency of linear indexing. Removed code to call imread, which was unused in any case.

21 Jan 2015

Updated usage notes

23 Jan 2015

Fixed a bug when using TIFFStack to load an entire stack, with ts(:);

Contact us