Multipage TIFF stack

Much faster than 'imwrite' and supports complex number images.
Updated 18 Oct 2019

View License

function res = saveastiff(data, path, options)
: 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 (When using JPEG compression, ImageWidth,
ImageLength, and RowsPerStrip must be multiples of 16.)
'adobe' : lossless Adobe-style
: JPEG compression qualtiy. A value between 1.0 and 100.0
: TRUE or false.
If this is false, all messages are skipped.
: true or FALSE
If path is exist, the data is appended to an existing file.
If path is not exist, this options is ignored.
: true or FALSE
Overwrite to an existing file.
: true or FALSE,
Use 64 bit addressing and allows for files > 4GB

Defalut value of 'options' is
options.color = false;
options.compress = 'no';
options.message = true;
options.append = false;
options.overwrite = false;
options.big = false;

res : Return value. It is 0 when the function is finished with no error.
If an error is occured in the function, it will have a positive
number (error code).

Cite As

Yoon-Oh Tak (2024). Multipage TIFF stack (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

It is possible to set the JPEG compression rate using the options.jpegquality option.
RowsPerStrip is set to 512. (It affects file saving speed and compression rate.
Fixed a bug where the data type was loaded into double only.

Bug fix: checking directory and filename in 'loadtiff.m'

Bug fix: RowsPerStrip of JPEG compression has to be a multiple of 16.

Added a file opening error checking routine.

Hello, Mark. I fixed my code a little bit. Please check this new version. I think it will be faster than before.

Now you can save a complex number image such as Fourier's coefficient image.
Pixels in a color image also can have complex numbers.
The fourth channel on a color image will be regarded as an alpha blending channel.

Now you can save image to a sub directory.
Now you can save image to a sub directory.
Now you can save image to a sub directory.

Now it supports 'uint64' and 'int64' data type.
Bug fixed: Temporary file will be deleted before creating new tiff file. (thanks to Peter Quicke)
I uploaded an old version yesterday. It was my mistake.... This is a new version.

There was a mistake in the version 2.5, and I fixed it. Thank you, Eyal.

Bug fix and add 'big' option for BigTIFF format (Thanks to Urs Utzinger).

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.

bug fix

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

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

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

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.

bug fix

Parameter 'options' is added.

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

Support lossy JPEG Compression.
bug fixed.