필터 지우기
필터 지우기

Matlab only opens first frame of multi-page tiff stack

조회 수: 28 (최근 30일)
Steven
Steven 2013년 11월 29일
답변: Ashish Uthama 2022년 2월 25일
I've created multi-page tiff files with a macro in ImageJ, and I'm now trying to open it using matlab, but I can only access the first frame.
Here is the result of imfinfo(filename). Accordingly, I get
length(imfinfo(filename)) = 1
Filename: [1x129 char]
FileModDate: '28-nov-2013 12:27:51'
FileSize: 6.7905e+09
Format: 'tif'
FormatVersion: []
Width: 512
Height: 512
BitDepth: 8
ColorType: 'grayscale'
FormatSignature: [77 77 0 42]
ByteOrder: 'big-endian'
NewSubFileType: 0
BitsPerSample: 8
Compression: 'Uncompressed'
PhotometricInterpretation: 'BlackIsZero'
StripOffsets: 932625
SamplesPerPixel: 1
RowsPerStrip: 512
StripByteCounts: 262144
XResolution: []
YResolution: []
ResolutionUnit: 'None'
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.47q
images=25900
slices=25900
loop=false
However if I open the same tif file in ImageJ, then I can read and scroll through the 25900 frames...The weird thing is that matlab can read previous multipage tiff I had created in imageJ without my batch macro...
I don't understand what's happening...any help would be greatly appreciated ! Thanks, Steven

채택된 답변

Christoph
Christoph 2014년 4월 28일
편집: Image Analyst 2019년 10월 17일
ImageJ only writes the first IFD for TIFF files larger than 4GB at the beginning of the file.
The other IFD entries are placed at the end of the TIFF file.
ImageJ is able to read such files because it sees "images=n" in the ImageDescription tag and realizes it needs to open n images.
As a workaround in MATLAB, you can try whether below code works. Note: This code assumes that the TIFF image has Stripped Planar Configuration and contains one strip per image. This might not work for all images but it could provide you a general idea about how to read such files generated by ImageJ using low-level I/O functions.
fileName = 'Mylarge.tif'; % Determine the number of image frames and the offset to the first image
info = imfinfo(fileName)
This may yield something similar to (amongst others)
FileSize: 1.055313188500000e+10
Format: 'tif'
FormatVersion: []
Width: 692
Height: 520
BitDepth: 16
ColorType: 'grayscale'
FormatSignature: [77 77 0 42]
ByteOrder: 'big-endian'
NewSubFileType: 0
BitsPerSample: 16
Compression: 'Uncompressed'
PhotometricInterpretation: 'BlackIsZero'
StripOffsets: 3342765
SamplesPerPixel: 1
RowsPerStrip: 520
StripByteCounts: 719680
Now determine the number of frames:
numFramesStr = regexp(info.ImageDescription, 'images=(\d*)', 'tokens');
numFrames = str2double(numFramesStr{1}{1});
% Use low-level File I/O to read the file
fp = fopen(fileName , 'rb');
% The StripOffsets field provides the offset to the first strip. Based on
% the INFO for this file, each image consists of 1 strip.
fseek(fp, info.StripOffsets, 'bof');
% Assume that the image is 16-bit per pixel and is stored in big-endian format.
% Also assume that the images are stored one after the other.
% For instance, read the first 100 frames
framenum=100;
imData=cell(1,framenum);
for cnt = 1:framenum
imData{cnt} = fread(fp, [info.Width info.Height], 'uint16', 0, 'ieee-be')';
end
fclose(fp);
  댓글 수: 1
Ashish Uthama
Ashish Uthama 2021년 9월 27일
Potential explanation for "The weird thing is that matlab can read previous multipage tiff I had created in imageJ without my batch macro...": I believe ImageJ switches to this (non-standard) tiff format when image size goes beyond 4GB, so if your previous images were smaller they would have been standard TIFF files that MATLAB could recognize.

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

추가 답변 (1개)

Ashish Uthama
Ashish Uthama 2022년 2월 25일
MATLAB R2020b has tiffreadVolume which supports non-BigTIFF volumes, greater than 4GB, created by ImageJ.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by