Get from Ico-github-logo

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
DylanMuir/TIFFStack

  • TS_UnitTest(strFilename)
    TS_UnitTest - FUNCITON Unit test for TIFFStack
  • tiffread31_header(file_name)
    set defaults values:
  • tiffread31_info(file_name)
    set defaults values:
  • tiffread31_readimage(TIF,...
    - Preallocate data block
  • TIFFStack
    TIFFStack - Manipulate a TIFF file like a tensor
  • View all files

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

4.66667
4.7 | 3 ratings Rate this file 20 Downloads (last 30 days) File Size: 1.52 MB File ID: #32025 Version: 1.22
image thumbnail

DylanMuir/TIFFStack

by

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
Description

See also http://dylan-muir.com/articles/tiffstack/
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 2015.
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.

Construction:
>> 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
  Properties:
         bInvert: 0
     strFilename: [1x9 char]
      sImageInfo: [5x1 struct]
    strDataClass: 'uint16'
Usage:
>> 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
Support for de-interleaving of channels and slices into the frame axis is also supported (see help text for TIFFStack).

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

Acknowledgements

This file inspired Alexludwigklein/Matlab Videos.

Required Products MATLAB
MATLAB release MATLAB 7.11 (R2010b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (22)
08 Nov 2016 Dylan Muir

Dylan Muir (view profile)

Hi Rachel,

I will take a look at the problem to see if I can reproduce it. I have created an issue on github (https://github.com/DylanMuir/TIFFStack/issues/14) to track this; please check there and respond if necessary.

Best regards,
Dylan.

Comment only
08 Nov 2016 Adrien Peyrache

Hi,

I am running into a problem with TiffStack specifically when I try to load >4GB uint16 tiff stacks that have been saved in imageJ (ie 'big stacks' dealt with by the 'OpenImageJBigStack' fx).

After TiffStack is done running on these faulty-headed tiff files (successfully calling MappedTensor), when I plot frames from the resultant tsStack object, for example using imagesc(tsStack(:,:,1)), the image appears circularly shifted along the 1st dimension, as Avinash mentioned in the comments section of your MappedTensor fx on FileExchange. Unfortunately, the fix mentioned in your response doesn't work for me (I'm assuming the output of >4GB ImageJ tiff stacks that display the error re: headers are binarized, as mentioned elsewhere).

All is working for tiff stacks saved in imageJ that are smaller than this limit.

Any help re: how to trouble shoot would be fantastic - as this fx for my smaller files is a life-savor for setting up efficient parallel processing.

Thanks!
Rachel

Comment only
28 Oct 2016 Dylan Muir

Dylan Muir (view profile)

Hi Sandeep,

TIFFStack uses compiled code for some operations, to speed up manipulations of an image stack. This requires the MEX compiler from matlab to be properly configured for your system. TIFFStack will work without these compiled versions, but will be slower. If you would like to use the MEX versions, then you will have to configure your system to successfully compile code.

Cheers,
Dylan.

Comment only
28 Oct 2016 sandeep manandhar

Hi,

I get this warning
--- TIFFStack: Compiling MEX functions.
Warning: --- TIFFStack: Could not compile MEX functions. Using
slow matlab versions.
> In TIFFStack>GetMexFunctionHandles (line 1728)
In TIFFStack (line 205)

My Matlab version is 8.6.0.267246 (R2015b).

Comment only
12 Jun 2016 Rob Campbell

Rob Campbell (view profile)

 
11 May 2016 Vijay Iyer

Please disregard my previous rating. I have not used the tool, so cannot rate or comment on it fairly. I was testing something randomly & apparently rating entries get submitted without pressing the submit button. Apologies for the noise! Long live signal.

Comment only
11 May 2016 Vijay Iyer  
16 Apr 2016 Xu

Xu (view profile)

Hi, I've figured out the problem by repairing my Visual Studio 2013. Thanks at all!

Comment only
16 Apr 2016 Xu

Xu (view profile)

Somehow my problem description got lost. Could you please help?

--- TIFFStack: Compiling MEX functions.
Warning: --- TIFFStack: Could not compile MEX functions. Using slow matlab versions.
> In TIFFStack.TIFFStack>GetMexFunctionHandles at 1703
In TIFFStack.TIFFStack>TIFFStack.TIFFStack at 205
In temp at 29

Comment only
16 Apr 2016 Xu

Xu (view profile)

additional information:

>> ver
----------------------------------------------------------------------------------------------------
MATLAB Version: 8.4.0.150421 (R2014b)
MATLAB License Number: 981334
Operating System: Microsoft Windows 7 Professional Version 6.1 (Build 7601: Service Pack 1)
Java Version: Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode

Comment only
11 Feb 2016 Sébastien MAILFERT

Hi Dylan,
You are right, the path was not correcly defined.

Now, my questions is how can I use the mex compiler please?
Best regards.

Comment only
10 Feb 2016 Dylan Muir

Dylan Muir (view profile)

Hi Sébastien,

The warning indicates that matlab can't use the mex compiler, which is required by TIFFStack for accelerated reading.

The error indicates that matlab can't find the file 'tiffread31_header.m', which is the 'private' subdirectory of TIFFStack. The TIFFStack directory needs to be added to the matlab path; perhaps you could check that.

I just downloaded the latest version, and can't reproduce the problem, even if I force TIFFStack to use the non-MEX versions of the access functions.

If you have further problems, please start an issue on github.

Best regards,
Dylan.

Comment only
10 Feb 2016 Sébastien MAILFERT

Hello,

I tried your function and I saw this error:

Warning: --- TIFFStack: Using slower non-TiffLib access.
> In TIFFStack (line 187)
Warning: --- TIFFStack: Could not compile MEX functions. Using slow matlab versions.
> In TIFFStack>GetMexFunctionHandles (line 1354)
In TIFFStack (line 192)
Error using TIFFStack (line 390)
*** TIFFStack: Could not open file
[T:\dark0.tif].

Caused by:
Undefined function 'tiffread31_header' for input arguments of type 'char'.

Could you help me please?

Comment only
15 Jul 2015 Dylan Muir

Dylan Muir (view profile)

Hi HCYU, Please pull the latest version and try again. There was a referencing bug for older versions of matlab -- I think this may have been your issue.
Best regards, Dylan.

Comment only
15 Jul 2015 HCYU

HCYU (view profile)

new error message below:

Error using TIFFStack>TS_read_data_Tiff (line 761)
*** TIFFStack: Could not read data from image file.

Error in TIFFStack/subsref (line 438)
tfData = TS_read_data_Tiff(oStack, S.subs, bLinearIndexing);

Error in testvaa3d (line 6)
img = iStack(:, :, i);

Caused by:
Error using tifflib
Directory numbers must be greater than or equal to 1.

Comment only
15 Jul 2015 Dylan Muir

Dylan Muir (view profile)

Hi HCYU, thanks for your bug report. I have fixed the bug in the latest commit of TIFFStack. You can pull it immediately from github; the file exchange version takes a day to update.
Best regards, Dylan.

Comment only
14 Jul 2015 HCYU

HCYU (view profile)

note that: "tfData = oStack.sImageInfo(1).MaxSampleValue - (tfData - oStack.sImageInfo(1).MinSampleValue);"

error info:"Error using -
Integers can only be combined with integers of the same class, or scalar doubles."

Comment only
24 Apr 2015 Dylan Muir

Dylan Muir (view profile)

Hi David, thanks for your message. I'm sorry about that regression. I've uploaded a new version which fixes the problem.
Best regards, Dylan,

Comment only
24 Apr 2015 David

David (view profile)

With the most recent version getting errors when accessing object properties like strDataClass

Error using cellfun
Input #2 expected to be a cell array, was char instead.

Error in TIFFStack/subsref (line 289)
cellfun(@isvalidsubscript, S.subs);

Comment only
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.

Updates
24 Jul 2011 1.1

Fixed a bug when indexing non-square TIFF files.

27 Jul 2011 1.2

Fixed a bug when referencing slice 58 of a stack.

16 Aug 2011 1.3

Updated screenshot

30 Sep 2011 1.4

Updated link to Francois Nedelec

07 Nov 2011 1.5

Updated description

05 Sep 2013 1.6

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

05 Mar 2014 1.7

Updated description

26 Mar 2014 1.8

Updated description

17 Jun 2014 1.9

Updated description

23 Oct 2014 1.10

Fixed a bug in indexing into an image file

04 Nov 2014 1.11

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

09 Nov 2014 1.12

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

08 Dec 2014 1.13

Added paper reference.

20 Jan 2015 1.14

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

21 Jan 2015 1.15

Updated usage notes

23 Jan 2015 1.16

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

23 Apr 2015 1.17

Improved referencing to make it more similar to matlab tensors. Fixed a referencing bug involving a confusion between "58" and ":".

23 Apr 2015 1.18

Improved referencing for edge cases.

24 Apr 2015 1.19

Fixed a regression when referencing object properties

18 Aug 2015 1.20

Moved TIFFStack to github hosting

19 Nov 2015 1.21

Reinstated description

02 Feb 2016 1.21

Added information that de-interleaving is supported

03 Aug 2016 1.21

Added "neuroscience" tag

22 Sep 2016 1.22

Updated paper citation

15 Oct 2016 1.22

Updated description

01 Dec 2016 1.22

Updated description

Contact us