Clear Filters
Clear Filters

load multipages TIF image

6 views (last 30 days)
Hello
I'm trying to open a multislices TIF image.
It works in GUI but when used in app designer it read only 1 slice.
What's wrong?
Many thanks for helps
I used this code:
function LoadImageButtonValueChanged(app, event)
value = app.LoadImageButton.Value;
% Selecting image file to process
[filename, pathname] = uigetfile('*.*', 'pick an image'); % pop up file open dialog to select image
filename = strcat(pathname,filename);
info = imfinfo(filename);
numberOfPages = length(info);
for k = 1 : numberOfPages
thisPage = imread(filename, k);
imshow(imadjust(thisPage),'Parent',app.UIAxes); %-show the kth image in this multipage tiff file
end
end
  2 Comments
Walter Roberson
Walter Roberson on 12 Feb 2023
filename = strcat(pathname,filename);
should be
filename = fullfile(pathname, filename);
uigetfile does not promise that the directory name will have a directory separator at the end of it.
alfonso Davide pinelli
alfonso Davide pinelli on 12 Feb 2023
Hello,
thanks for your support.
Still Not working. Command windows state
Warning: The next image file directory at byte position 117206199 is at or beyond the end of the file.

Sign in to comment.

Accepted Answer

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 12 Feb 2023
Here length() does not do the job. therefore, it is better to use tiffreadVolume()
Here is the corrected code:
function LoadImageButtonValueChanged(app, event)
value = app.LoadImageButton.Value;
% Selecting image file to process
[filename, pathname] = uigetfile('*.*', 'pick an image'); % pop up file open dialog to select image
filename = strcat(pathname,filename);
info = tiffreadVolume(filename);
Size_Tiff = size(info);
numberOfPages = Size_Tiff(4);
for k = 1 : numberOfPages
thisPage = imread(filename, k);
imshow(imadjust(thisPage),'Parent',app.UIAxes); %-show the kth image in this multipage tiff file
end
end
  11 Comments
Steve Eddins
Steve Eddins on 14 Feb 2023
Without a sample file to examine, I can only guess. Based on the imfinfo output you posted, as well as Walter Roberson's comments, I guess that the slice data is hidden inside private TIFF tags created by ImageJ. See the ImageDescription and UnknownTags fields of the output of imfinfo. If that is really the case, then it will require custom code to convert the private tag ImageJ data. I'm not familiar with the method of storing extra slice data in a TIFF file, so I'm not sure how difficult it might be.
Walter Roberson
Walter Roberson on 14 Feb 2023
You need to be careful using length(). length(A) is defined as
if isempty(A)
length is 0
else
length is max(size(A))
end
We see from your previous comments that size() of the tiffreadVolume is [512 512] . length() of that is not the number of pages: length() is going to be max([512 512]) which would be 512
Number of pages would, in the specific case of tiffreadVolume, be size(info,3) -- which would be 1 for that file.

Sign in to comment.

More Answers (1)

alfonso Davide pinelli
alfonso Davide pinelli on 16 Feb 2023
The image was corrupted.
The code is ok.
Many thanks for all of you

Community Treasure Hunt

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

Start Hunting!