TIFF save file not working
조회 수: 3 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Mann Baidi
2024년 7월 23일
You are facing this issue because you are not setting the values of the parameteres for the new IFD created using writeDirectory function. You will have to set tag for each directories.
If you want to keep the same parameter for every directory, you can update your code as below:
% imposta le informazioni nella nuova immagine Tiff
tagstruct.Photometric= 1;
tagstruct.Compression= 1; % 1 = nessuna compressione, 8 = compressione Deflate
tagstruct.BitsPerSample= info(1).BitsPerSample;
tagstruct.SamplesPerPixel= info(1).SamplesPerPixel;
tagstruct.SampleFormat= Tiff.SampleFormat.UInt;
tagstruct.ImageLength= info(1).Height;
tagstruct.ImageWidth= info(1).Width;
tagstruct.PlanarConfiguration= Tiff.PlanarConfiguration.Chunky;
for j = 1:numel(info)
%tagstruct(info(j)); % commenta questa riga per testare se il problema è qui
t.writeDirectory();
t.setTag(tagstruct)
t.write(newStack(:,:,j));
end
t.close();
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!