TIFF save file not working
Hello, I have a 32bit grayscale tiff image composed by 41 slices.
I’m saving file always as a stack but it dont works:
Error using Tiff/writeAllStrips
Unable to retrieve ImageLength.
Error in Tiff/write (line 1486)
obj.writeAllStrips(varargin{:});
This is the portion of code
% salva il nuovo file con lo stesso nome ma aggiungendo "modified"
newFilename = fullfile(folder, [fileList(i).name(1:end-4) ‘_modified.tif’]);
t = Tiff(newFilename, ‘w’);
% ottieni le informazioni dalla prima immagine dello stack originale
info = imfinfo(filename);
disp(info(1))
% tagstruct.ImageLength = size(newStack(:,:,1),1);
% tagstruct.ImageWidth = size(newStack(:,:,1),2);
% tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
% tagstruct.BitsPerSample = 32;
% tagstruct.SamplesPerPixel = 1;
% tagstruct.RowsPerStrip = 16;
% tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
% tagstruct.Software = ‘MATLAB’;
% imposta le informazioni nella nuova immagine Tiff
t.setTag(‘Photometric’, 1);
t.setTag(‘Compression’, 1); % 1 = nessuna compressione, 8 = compressione Deflate
t.setTag(‘BitsPerSample’, info(1).BitsPerSample);
t.setTag(‘SamplesPerPixel’, info(1).SamplesPerPixel);
t.setTag(‘SampleFormat’, Tiff.SampleFormat.UInt);
t.setTag(‘ImageLength’, info(1).Height);
t.setTag(‘ImageWidth’, info(1).Width);
t.setTag(‘PlanarConfiguration’, Tiff.PlanarConfiguration.Chunky);
for j = 1:numImages
%t.setTag(info(j)); % commenta questa riga per testare se il problema è qui
t.write(newStack(:,:,j));
t.writeDirectory();
end
t.close();
This is iminfo of source file
FileModDate: ’30-dic-2022 09:47:14′
FileSize: 492005745
Format: ‘tif’
FormatVersion: []
Width: 2000
Height: 1500
BitDepth: 32
ColorType: ‘grayscale’
FormatSignature: [77 77 0 42]
ByteOrder: ‘big-endian’
NewSubFileType: 0
BitsPerSample: 32
Compression: ‘Uncompressed’
PhotometricInterpretation: ‘BlackIsZero’
StripOffsets: 225
SamplesPerPixel: 1
RowsPerStrip: 1500
StripByteCounts: 12000000
XResolution: []
YResolution: []
ResolutionUnit: ‘Inch’
Colormap: []
PlanarConfiguration: ‘Chunky’
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 4.2950e+09
MinSampleValue: 0
Thresholding: 1
Offset: 8
ImageDescription: ‘ImageJ=1.53n↵images=41↵slices=41↵loop=false↵min=0.0↵max=1.401298464324817E-45↵’
SampleFormat: ‘IEEE floating point’
Many thanksHello, I have a 32bit grayscale tiff image composed by 41 slices.
I’m saving file always as a stack but it dont works:
Error using Tiff/writeAllStrips
Unable to retrieve ImageLength.
Error in Tiff/write (line 1486)
obj.writeAllStrips(varargin{:});
This is the portion of code
% salva il nuovo file con lo stesso nome ma aggiungendo "modified"
newFilename = fullfile(folder, [fileList(i).name(1:end-4) ‘_modified.tif’]);
t = Tiff(newFilename, ‘w’);
% ottieni le informazioni dalla prima immagine dello stack originale
info = imfinfo(filename);
disp(info(1))
% tagstruct.ImageLength = size(newStack(:,:,1),1);
% tagstruct.ImageWidth = size(newStack(:,:,1),2);
% tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
% tagstruct.BitsPerSample = 32;
% tagstruct.SamplesPerPixel = 1;
% tagstruct.RowsPerStrip = 16;
% tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
% tagstruct.Software = ‘MATLAB’;
% imposta le informazioni nella nuova immagine Tiff
t.setTag(‘Photometric’, 1);
t.setTag(‘Compression’, 1); % 1 = nessuna compressione, 8 = compressione Deflate
t.setTag(‘BitsPerSample’, info(1).BitsPerSample);
t.setTag(‘SamplesPerPixel’, info(1).SamplesPerPixel);
t.setTag(‘SampleFormat’, Tiff.SampleFormat.UInt);
t.setTag(‘ImageLength’, info(1).Height);
t.setTag(‘ImageWidth’, info(1).Width);
t.setTag(‘PlanarConfiguration’, Tiff.PlanarConfiguration.Chunky);
for j = 1:numImages
%t.setTag(info(j)); % commenta questa riga per testare se il problema è qui
t.write(newStack(:,:,j));
t.writeDirectory();
end
t.close();
This is iminfo of source file
FileModDate: ’30-dic-2022 09:47:14′
FileSize: 492005745
Format: ‘tif’
FormatVersion: []
Width: 2000
Height: 1500
BitDepth: 32
ColorType: ‘grayscale’
FormatSignature: [77 77 0 42]
ByteOrder: ‘big-endian’
NewSubFileType: 0
BitsPerSample: 32
Compression: ‘Uncompressed’
PhotometricInterpretation: ‘BlackIsZero’
StripOffsets: 225
SamplesPerPixel: 1
RowsPerStrip: 1500
StripByteCounts: 12000000
XResolution: []
YResolution: []
ResolutionUnit: ‘Inch’
Colormap: []
PlanarConfiguration: ‘Chunky’
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 4.2950e+09
MinSampleValue: 0
Thresholding: 1
Offset: 8
ImageDescription: ‘ImageJ=1.53n↵images=41↵slices=41↵loop=false↵min=0.0↵max=1.401298464324817E-45↵’
SampleFormat: ‘IEEE floating point’
Many thanks Hello, I have a 32bit grayscale tiff image composed by 41 slices.
I’m saving file always as a stack but it dont works:
Error using Tiff/writeAllStrips
Unable to retrieve ImageLength.
Error in Tiff/write (line 1486)
obj.writeAllStrips(varargin{:});
This is the portion of code
% salva il nuovo file con lo stesso nome ma aggiungendo "modified"
newFilename = fullfile(folder, [fileList(i).name(1:end-4) ‘_modified.tif’]);
t = Tiff(newFilename, ‘w’);
% ottieni le informazioni dalla prima immagine dello stack originale
info = imfinfo(filename);
disp(info(1))
% tagstruct.ImageLength = size(newStack(:,:,1),1);
% tagstruct.ImageWidth = size(newStack(:,:,1),2);
% tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
% tagstruct.BitsPerSample = 32;
% tagstruct.SamplesPerPixel = 1;
% tagstruct.RowsPerStrip = 16;
% tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
% tagstruct.Software = ‘MATLAB’;
% imposta le informazioni nella nuova immagine Tiff
t.setTag(‘Photometric’, 1);
t.setTag(‘Compression’, 1); % 1 = nessuna compressione, 8 = compressione Deflate
t.setTag(‘BitsPerSample’, info(1).BitsPerSample);
t.setTag(‘SamplesPerPixel’, info(1).SamplesPerPixel);
t.setTag(‘SampleFormat’, Tiff.SampleFormat.UInt);
t.setTag(‘ImageLength’, info(1).Height);
t.setTag(‘ImageWidth’, info(1).Width);
t.setTag(‘PlanarConfiguration’, Tiff.PlanarConfiguration.Chunky);
for j = 1:numImages
%t.setTag(info(j)); % commenta questa riga per testare se il problema è qui
t.write(newStack(:,:,j));
t.writeDirectory();
end
t.close();
This is iminfo of source file
FileModDate: ’30-dic-2022 09:47:14′
FileSize: 492005745
Format: ‘tif’
FormatVersion: []
Width: 2000
Height: 1500
BitDepth: 32
ColorType: ‘grayscale’
FormatSignature: [77 77 0 42]
ByteOrder: ‘big-endian’
NewSubFileType: 0
BitsPerSample: 32
Compression: ‘Uncompressed’
PhotometricInterpretation: ‘BlackIsZero’
StripOffsets: 225
SamplesPerPixel: 1
RowsPerStrip: 1500
StripByteCounts: 12000000
XResolution: []
YResolution: []
ResolutionUnit: ‘Inch’
Colormap: []
PlanarConfiguration: ‘Chunky’
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 4.2950e+09
MinSampleValue: 0
Thresholding: 1
Offset: 8
ImageDescription: ‘ImageJ=1.53n↵images=41↵slices=41↵loop=false↵min=0.0↵max=1.401298464324817E-45↵’
SampleFormat: ‘IEEE floating point’
Many thanks tiff, save MATLAB Answers — New Questions