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

5 Ansichten (letzte 30 Tage)
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?

Antworten (1)

Mann Baidi
Mann Baidi am 26 Dez. 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!

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by