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

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.
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.

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

 채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 2월 12일

0 개 추천

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

Hello,
why Size_Tiff(4) ?
My code show error :
Index exceeds the number of array elements. Index must not exceed 2.
If I use Sixe_Tiff(2) as suggested it show
Error using imread/call_format_specific_reader
TIFF library error - 'TIFFFetchDirectory: Can not read TIFF directory count.'
Error in imread (line 444)
[X, map] = call_format_specific_reader();
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 2월 12일
Pl., share one of your tif images to give you a proper guidance.
Walter Roberson
Walter Roberson 2023년 2월 12일
V = tiffreadVolume(filename) loads all of the volumetric or time series image data in the multipage TIFF file named filename into V. The spatial and time dimensions in V are first, and color (if present) is in the final dimension.
This implies that if a 3D array is returned that it would be height by width by pages (time), and that if it is 4D then it would be height by width by pages (time) by colorpanes .
This is not the same order as is more commonly used in MATLAB; for example writing video frames is height by width by colorpanes by time. It would be easy to mistakenly think that the pages (time) would be the 4th dimension of the output instead of the third that is documented.
But if Size_Tiff is showing up as 2, then tiffreadVolume was only able to find a single image.
Warning: The next image file directory at byte position 117206199 is at or beyond the end of the file.
The TIFF file is not formatted properly. It might be corrupt.
alfonso Davide pinelli
alfonso Davide pinelli 2023년 2월 13일
편집: alfonso Davide pinelli 2023년 2월 13일
Thanks Sulaymon and Walter
I have several copy of this image file and It is seen always as only one image.
I opened it also with Fiji and I can see the slices.
I notice, anyway, that also earlier version of my code, also other codes actually, that are using this part of code,now they no more working.
I didn't mady any changement in the code, dut now it show ony one image.
There are something in the configuration of matlab, directory...? I don't know.
Many thanks for your support.
Walter Roberson
Walter Roberson 2023년 2월 13일
There are multiple ways of storing volumes in a single TIFF file. The documentation says
This function supports reading volumetric and time series data from the following kinds of TIFF stacks:
  • Image data stored in the file as individual Image File Directories (IFDs) of the same size and kind.
  • Image data stored in the file as one image using the TIFF ImageDepth tag .
  • Image data stored as large, non-BigTIFF files, greater than 4GB, created by ImageJ.
(I note that the last of those is not really conformant TIFF files)
It would be interesting to analyze the tiff file using Tiff class to see how it is structured.
I'm looking if I may share the file (it is not mine) but I can share attribute
FileModDate: '24-gen-2023 14:33:04'
FileSize: 36905109
Format: 'tif'
FormatVersion: []
Width: 512
Height: 512
BitDepth: 8
ColorType: 'grayscale'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubFileType: 0
BitsPerSample: 8
Compression: 'Uncompressed'
PhotometricInterpretation: 'BlackIsZero'
StripOffsets: 27831
SamplesPerPixel: 1
RowsPerStrip: 512
StripByteCounts: 262144
XResolution: []
YResolution: []
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 255
MinSampleValue: 0
Thresholding: 1
Offset: 8
ImageDescription: 'ImageJ=1.47v↵images=447↵slices=447↵loop=false↵min=0.0↵max=3.0↵'
UnknownTags: [2×1 struct]
this part is not doig the job but I don't know why
info = imfinfo(filename)
alfonso Davide pinelli
alfonso Davide pinelli 2023년 2월 14일
이동: Walter Roberson 2023년 2월 14일
Hello Walter
I'm trying to use tiffereadvolume, but it report me 512 as dimension, but i'm looking for 447 as the number of slices
>> filename = uigetfile('*.*');
>> info = tiffreadVolume(filename);
>> numberOfPages = length(info)
numberOfPages =
512
Steve Eddins
Steve Eddins 2023년 2월 14일
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.
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.

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

추가 답변 (1개)

alfonso Davide pinelli
alfonso Davide pinelli 2023년 2월 16일

0 개 추천

The image was corrupted.
The code is ok.
Many thanks for all of you

카테고리

도움말 센터File Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by