Maximum number of frames in unint16 class tiff image (using libtiff).

7 views (last 30 days)
Hi there, I have a (long) time series of uint16 xyt dataset which I want to save as tiff.
I used
filename = 'testtifffp.tiff';
t = Tiff( filename,'w' );
sz = size(d);
tagstruct.ImageLength = size(d, 1);
tagstruct.ImageWidth = size(d, 2);
%tagstruct.ImageDepth = size(d, 3);
tagstruct.SampleFormat = Tiff.SampleFormat.UInt;
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.BitsPerSample = 16;
tagstruct.SamplesPerPixel = 1;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
for z = 1:min(sz(3),8189)
t.setTag(tagstruct);
t.write(d(:,:,z));
if z < sz(3)
t.writeDirectory();
fprintf('%%')
end
if ~rem(z,128);fprintf('\n');end
end
fprintf('\n');
t.close();
but reach the problem that I cannot write more than 8189 frames.
At frame 8190 I get
Error using tifflib
Unable to write strip #1.
Error in Tiff/writeAllStrips (line 1982)
tifflib('writeEncodedStrip',obj.FileID, stripNum-1,imageData(row_inds,:));
Error in Tiff/write (line 1486)
obj.writeAllStrips(varargin{:});
Error in NisargsBrain (line 125)
t.write(d(:,:,z));
the easier command
t.write(d);
causes the following error
t.write(d);
Warning: Sum of Photometric color channels and ExtraSamples does not match the value specified in SamplesPerPixel.
Writing with this configuration will error in a future release. To correct the configuration, define the non-color channels as ExtraSamples.
Error using tifflib
Unable to write strip #1.
Error in Tiff/writeAllStrips (line 1980)
tifflib('writeEncodedStrip',obj.FileID,stripNum-1,imageData(row_inds,:,:));
Error in Tiff/write (line 1486)
obj.writeAllStrips(varargin{:});
It is probably the same problem.
Is there any option to save more than 8189 frames when
sz = size(d)
sz =
512 512 16384
?
Any solution?
>> versionString = Tiff.getVersion()
versionString =
'LIBTIFF, Version 4.4.0
Copyright (c) 1988-1996 Sam Leffler
Copyright (c) 1991-1996 Silicon Graphics, Inc.'

Accepted Answer

DGM
DGM on 28 Mar 2023
Moved: DGM on 28 Mar 2023
I don't think this is a limitation on the number of channels. I think you're simply running into the 4GB limit and would need to use BigTIFF to create a larger file. The best way to do that in MATLAB? I'm not sure off the top of my head.
  2 Comments
Andre Zeug
Andre Zeug on 28 Mar 2023
🙈 Oh yeah, file size just reaches 4GB, would compression help (a bit) to stay below 4GB?
DGM
DGM on 28 Mar 2023
Edited: DGM on 28 Mar 2023
I am not sure what aspect of addressing gives rise to the limitation, so I'm not sure if that's 4GB of image data or 4GB of file size. I don't really have the memory to do much testing.
If you want to avoid trying to figure out what it takes to use BigTIFF, you might try it. The achieveable compression ratio would be dependent on the data and the compression method used..

Sign in to comment.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!