TIFFs in MATLAB
MATLAB uses the open source library libtiff to write TIFF files, or they did the last time I asked. I work with multipage TIFFs a lot, and I find MATLAB is not very fast at reading and writing these large TIFF files. I use the same library in my own C++ code, and it is exactly a billion times faster.
They’ve improved the multipage TIFF file reading. Perhaps they were motivated by a particularly blunt assessment in their online forums. Here’s an excerpt:
“No offense meant […] but in my opinion if Java (i.e. ImageJ) does it faster than you then you are clearly doing something wrong. ” -V.B.
Last year Steve and MathWorks made improvements (note that several of the comments are from neuroscientists). Here’s a benchmark: “I compared R2008b and R2009a for reading 65,000 images from a TIFF file. It took just under an hour in R2008b, for an average of about 21 seconds per image. It took about 90 seconds in R2009a, for an average of about 1.5 milliseconds per image.” Using this technique requires modifying your code, as described here.
It’s still not as fast as ImageJ, so they have plenty of room for improvement. There has been talk of adding a simple wrapper for direct libtiff calls, but it’s not in MATLAB 2010a.
In order to get better speed, I recommend writing your own functions in C/C++ using libtiff, or, actually, its 64-bit doppelganger BigTIFF.
I wasn’t aware of this extra Matlab bit for loading multipage tiffs. Thanks for the tip!
imwrite(foo,’bar.tif’,’writemode’,’append’) SUCKS for big (500+ page) TIFF stacks. It N^2 slow, opening the file each time.
This is the killer app for multi-page TIFF writing in matlab. Way faster.
http://www.mathworks.com/matlabcentral/fileexchange/35684
…Interesting:
http://www.matlabtips.com/mathworks-has-listened-to-our-tiff-prays/
I did not test the bug-fixes yet, though.