View multiplage tiff in app designer

조회 수: 6 (최근 30일)
Josef Hinterlechner
Josef Hinterlechner 2020년 11월 12일
편집: Subhadeep Koley 2020년 11월 14일
I have the following function to import a Tiff-File, but it only shows the first slice of any tiff file. And I am currently not able to show the 2nd or nth slice in any way. How would this be possible?
function ImportTiffButtonPushed(app, event)
[file,path] = uigetfile('*.tif*');
if isequal(file,0)
else
imgPath = fullfile(path,file);
% open image and show it in the image box
tiffStack = imread(imgPath);
imshow(tiffStack, 'parent', app.UIAxes);
end

채택된 답변

Subhadeep Koley
Subhadeep Koley 2020년 11월 12일
편집: Subhadeep Koley 2020년 11월 14일
For multi-page file, imread only reads the first slice in the file (or a specific slice specified by an optional argument).
If you have MATLAB R2020b, you can use the function tiffreadVolume to read entire TIFF file. Otherwise, you can loop through imread and stack each slices (might be time consuming if the TIFF file is large).
function ImportTiffButtonPushed(app, event)
[file ,path] = uigetfile('*.tif*');
if isequal(file, 0)
else
imgPath = fullfile(path, file);
% Read the tiff file into tiffStack
tiffInfo = imfinfo(imgPath);
tiffStack = imread(imgPath, 1);
numImages = numel(tiffInfo);
for idx = 2:numImages
temp = imread(imgPath, idx);
tiffStack = cat(3 , tiffStack, temp);
end
% Display multiple slices as rectangular montage
montage(tiffStack, 'parent', app.UIAxes);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by