4.9 | 7 ratings Rate this file 44 Downloads (last 30 days) File Size: 7.07 KB File ID: #35684
image thumbnail

Save and load data as multi-frame TIFF format



16 Mar 2012 (Updated )

Export various types of data such as single, double or 16bit integer as TIFF format

| Watch this File

File Information

It supports 'uint8', 'uint16', 'uint32', 'int8', 'int16', 'int32', 'single' and 'double' data type.

  : true or FALSE
  : If this is true, third dimension should be 3 and the data is saved as a color image.
  : 'no', 'lzw', 'jpeg' or 'adobe'.
    Compression type.
      'no' : Uncompressed(Default)
      'lzw' : lossless LZW
      'jpeg' : lossy JPEG
      'adobe' : lossless Adobe-style
  : true or FALSE.
    If this is false, all messages are skipped.
  : true or FALSE. If this is false, always overwrite an existing file.
  : true or FALSE
    If path is exist, the data is appended to an existing file.
    If path is not exist, this options is ignored.

Defalut value of 'options' is
    options.color = false;
    options.comp = 'no';
    options.message = false;
    options.ask = false;
    options.append = false;

Examples :

[X,Y,Z] = peaks(100);
X = single(X);
Y = single(Y);
Z = single(Z);
Z_index = uint8((Z - min(Z(:))) * (255 / (max(Z(:)) - min(Z(:)))));
Z_color = uint8(ind2rgb(Z_index, hsv(256)*256));
Z_color_multiframe = reshape([Z_color(:)*0.2 Z_color(:)*0.6 Z_color(:)], 100, 100, 3, 3);
Z_color_noisy = uint8(single(Z_color) + rand(100, 100, 3).*50);

% 8-bit, grayscale image
saveastiff(uint8(Z_index), 'Z_uint8.tif');

% Lossless LZW compression
options.comp = 'lzw';
saveastiff(uint8(Z_index), 'Z_uint8_LZW.tif', options);
options.comp = 'no';

% Ask a question if the file is already exist
options.ask = true;
saveastiff(uint8(Z_index), 'Z_uint8_LZW.tif', options);
options.ask = false;

% Allow message printing.
options.message = true;
saveastiff(uint8(Z_index), 'Z_uint8_LZW.tif', options);
options.message = false;

% 16-bit, grayscale image
saveastiff(uint16(Z_index), 'Z_uint16.tif');

% 32-bit single, grayscale image
saveastiff(Z, 'Z_single.tif');

% RGB color image
options.color = true;
saveastiff(Z_color, 'Z_rgb.tif', options);
options.color = false;

% Save each R, G and B chanels of the color image, separately.
saveastiff(Z_color, 'Z_rgb_channel.tif');

% Save the multi-frame RGB color image
options.color = true;
saveastiff(Z_color_multiframe, 'Z_rgb_multiframe.tif', options);
options.color = false;

% Save the noise-added RGB color image
options.color = true;
saveastiff(Z_color_noisy, 'Z_rgb_noisy.tif', options);
options.color = false;

% 32-bit single, 50x50x50 volume data
saveastiff(single(rand(50, 50, 50)), 'volume_50x50x50.tif');

% Append option is ignored if path dose not exist.
options.append = true;
saveastiff(Z_index, 'Z_uint8_append.tif', options);
options.append = false;

% You can append any type of image to an existing tiff file.
options.append = true;
saveastiff(single(rand(10, 10, 3)), 'Z_uint8_append.tif', options);
options.color = true;
saveastiff(Z_color_multiframe, 'Z_uint8_append.tif', options);
options.color = false;
options.append = false;

Required Products MATLAB
MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
18 Mar 2014 Dmitry Sorokin  
08 Mar 2014 Jose Rosado  
19 Oct 2013 Shalin Mehta

This function provides approx. 10x speed up on a windows machine as compared to imwrite(..'append') loop. But, on mac (I presume also on Unix) the call to fileattrib (fileattrib(tempfile, '+h +w', '', 's');) throws an exception. saveastiff catches this exception and deletes the temp file without saying anything.

The exception occurs because +h (hidden) attribute is not valid on mac. Removing +h and -h from the calls to fileattrib fixes the problem.

29 Nov 2012 YoonOh Tak

Yes, Jurgen. You need Matlab 2009b or later.

29 Nov 2012 Jurgen

Oh nvm I don't have the Tiff class :(

29 Nov 2012 Jurgen

Doens't work for me, using MATLAB 2008a. Dont get any error but there is no savefile in my current directory.

21 Nov 2012 Weicheng Kuo

Fantastic performance!! :) Can't help but create an account to recommend it!

21 Aug 2012 Casey Ta

Very nice. I had to manually add support for PackBits, but this was very easy to do (compression tag value 32773). I did happen to notice one typo on line 202 where "optoins" should be "options".

15 Jun 2012 Andrew

So much faster than imwrite(foo, ; 'writemode','append') for large (500+ page) tiffs. Thank You!

16 May 2012 Mathew Thomas  
19 Mar 2012

Support lossy JPEG Compression.
bug fixed.

06 Apr 2012

There was a bug in the example.
  [X,Y,Z] = peaks(100);
is modified to
  [X,Y,Z] = single(peaks(100));

09 May 2012

Parameter 'options' is added.

10 May 2012

bug fix

11 May 2012

Bug fix
Now you can append an image data to an existing tiff file.
And any type of data can be appended to an existing file.

11 May 2012

Bug fixed.
Now, it supports 'double' precision.

27 Aug 2012

Ttypographical error on line 202 : optoins -> options
Thank you, Casey Ta.

20 Nov 2012

Bug fix: It crashed when the file is already opened.

06 Sep 2013

bug fix

21 Oct 2013

Bug fix.
Thank you, Dr. Shalin Mehta.
I added some 'ispc' codes to avoid the exception on mac. But I'm sorry that I couldn't test this version because I don't have mac os.

Contact us