What is the fastest way to get the number of pages in a multi-page TIFF file?
1 view (last 30 days)
Show older comments
I have a stack of images saved as a multi-page TIFF file. I want to extract the number of images (pages) without reading all of them into MATLAB.
Currently, I am using the following code:
info = imfinfo('myfile.tif');
n = length(info);
Is there a better/faster way?
0 Comments
Answers (1)
Mann Baidi
on 26 Dec 2024
Yes, you can achieve some performance improvement over using "imfinfo" by utilizing the TIFF object in MATLAB. You can write a script to iterate through the directories in the TIFF file and count them. Additionally, you can compare the performance enhancement for determining the number of pages in a TIFF file by executing the code provided below:
function numImages = countTiffPages(filename)
hTif = Tiff(filename,'r');
numImages = 1;
while ~hTif.lastDirectory()
numImages = numImages + 1;
hTif.nextDirectory();
end
hTif.setDirectory(1);
close(hTif);
end
tic
info = imfinfo('large_multistack_image.tiff');
n = length(info)
toc
tic
countTiffPages('large_multistack_image.tiff')
toc
For more information on the TIFF Object, please refer to the following documentation:
Hoping this willl resolve your query!
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!