What is the fastest way to get the number of pages in a multi-page TIFF file?

13 vues (au cours des 30 derniers jours)
Matthew Eicholtz
Matthew Eicholtz le 15 Fév 2016
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?

Réponses (1)

Mann Baidi
Mann Baidi le 26 Déc 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!

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by