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.

Tags: