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

15 ビュー (過去 30 日間)
Matthew Eicholtz
Matthew Eicholtz 2016 年 2 月 15 日
回答済み: Mann Baidi 2024 年 12 月 26 日
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?

回答 (1 件)

Mann Baidi
Mann Baidi 2024 年 12 月 26 日
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!

カテゴリ

Help Center および File ExchangeImage Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by