MATLAB R2009a – imread and multipage TIFFs
One of the changes we made to MATLAB in R2009a was to improve the way imread handles multipage TIFF files. (A multipage TIFF file is one that contains multiple images. I'm not sure, but I think this terminology stems from the use of TIFF to store FAX data.) As I've written about before, in the last few years some of our users have adopted a workflow that involves storing a large number of individual images in a single TIFF file. It turns out that the following loop had a bad performance characteristics:
fname = 'my_file_with_lots_of_images.tif'; info = imfinfo(fname); num_images = numel(info); for k = 1:num_images A = imread(fname, k); % ... Do something with image A ... end
One problem was that imfinfo took a long time when the file contained many images. A second problem was that the for-loop execution time scaled with num_images^2 instead of num_images. Neither problem was severe unless num_images was in the thousands, but then the bad scaling took over and made it unusable.
The reason for the bad scaling has to do with the image location is stored in the file as a kind of linked list. I've given more detail on this previously.
Step 1 in addressing the performance problem was to make imfinfo run a lot faster. This enhancement was made in one of the 2008 releases, either R2008a or R2008b. I forget which one.
Step 2, in R2009a, was to add new information to the output of imfinfo and a new syntax to imread to make the read step scale better. The output of imfinfo now includes the locations of every image in the file, and you can now pass that information to imread to help it locate a specific image more quickly.
Here's how the processing loop might look using R2009a:
fname = 'my_file_with_lots_of_images.tif'; info = imfinfo(fname); num_images = numel(info); for k = 1:num_images A = imread(fname, k, 'Info', info); % ... Do something with image A ... end
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.
We're not done yet with TIFF enhancements. TIFF is a very flexible format that is used in many different applications and industries. We have more enhancement requests logged related to TIFF than for all the other image formats combined. So we are continuing to devote resources to expanding what MATLAB users can do with TIFF files. If you have any particular requests related to TIFF, please comment on this post.
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.