What is the fastest way to get the number of pages in a multi-page TIFF file?
15 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Image Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!