How to show Tiff stacks

조회 수: 176 (최근 30일)
Soum
Soum 2013년 11월 11일
답변: Ashish Uthama 2022년 3월 2일
Hi everyone;
I'm trying to show a tiff stack '57 images as one file' but I faced this problem:
Warning: Can only display one frame from this multiframe file:
"Stack.tif".
> In imuitools\private\getImageFromFile at 20
In imuitools\private\imageDisplayParseInputs at 74
In imshow at 198
In Prg at 4
how can I display a tiff stack image? and after I applied some processes how can I collect them again 'refile them'

채택된 답변

Jeff E
Jeff E 2013년 11월 12일
You can read each tiff image in one at a time using imread (note I'm making some assumptions...like you do indeed have a multipage tiff):
tiff_info = imfinfo('2-A^11815^52071.tif'); % return tiff structure, one element per image
tiff_stack = imread('2-A^11815^52071.tif', 1) ; % read in first image
%concatenate each successive tiff to tiff_stack
for ii = 2 : size(tiff_info, 1)
temp_tiff = imread('2-A^11815^52071.tif', ii);
tiff_stack = cat(3 , tiff_stack, temp_tiff);
end
And you can then use the 'append' switch to write each tiff as a new image in a multi-page tiff:
%write a Tiff file, appending each image as a new page
for ii = 1 : size(tiff_stack, 3)
imwrite(tiff_stack(:,:,ii) , 'new_stack.tif' , 'WriteMode' , 'append') ;
end
  댓글 수: 3
Jeff E
Jeff E 2013년 11월 12일
If you mean separate tiff files, all in one directory, then change the first bit of code to use the output from DIR (again, assuming you have more than one tiff in a directory):
files = dir('C:\temp\*.tiff');
tiff_stack = imread(files(1).name);
for ii = 2 : size(files, 1)
temp_tiff = imread(files(ii).name);
tiff_stack = cat(3 , tiff_stack, temp_tiff);
end
If you meant something else, please elaborate.
Soum
Soum 2013년 11월 12일
thank you but I mean I've a 57 images .tiff 'separated' and I wanna read
them as one multipage tiff image

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Shep Bryan
Shep Bryan 2020년 4월 16일
In my case it ends up being a couple orders of magnitude faster to avoid using imread. Try:
function data = FastTiff(filename)
warning('off','all') % Suppress all the tiff warnings
tstack = Tiff(filename);
[I,J] = size(tstack.read());
K = length(imfinfo(filename));
data = zeros(I,J,K);
data(:,:,1) = tstack.read();
for n = 2:K
tstack.nextDirectory()
data(:,:,n) = tstack.read();
end
warning('on','all')
end
Notice that I suppress the warnings in my code because the format of my data is strange.

Ashish Uthama
Ashish Uthama 2022년 3월 2일
It would help to clarify the nature of your input files (Folder of tiffs? One tiff file with multiple IFD/s? Or one tiff file with ImageJ style stack?)
You could look at tiffreadvolume to read in the latter two types. And explore volshow and volumeViewer if its 3D data, or just implay if its a time series.
For stream processing, you could also explore blockedImage to read+process+write large 3D data from tiff files.

카테고리

Help CenterFile Exchange에서 Explore and Edit Images with Image Viewer App에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by