Reputation: 793
*strong text*I am trying to save a multi-page TIF file using the MATLAB TIFF class in 2012a by following the example in the documentation. My usage differs in that I am writing a 32-bit grayscale image with values ranging from approximately -10,000 to 200,000.
% Use 'a' for 'append' since this code is in a loop that writes each page.
% Note: 'fileName' is defined elsewhere and the file is created.
t = Tiff(fileName, 'a');
tagstruct.ImageLength = size(result, 2);
tagstruct.ImageWidth = size(result, 1);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.SampleFormat = Tiff.SampleFormat.IEEEFP;
tagstruct.Compression = Tiff.Compression.None;
tagstruct.BitsPerSample = 32;
tagstruct.SamplesPerPixel = 1;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.Software = 'MATLAB';
t.setTag(tagstruct);
% Viewing the data immediately before the 'write' operation shows it correct.
% imtool(result(:, :, j));
% Tools -> Adjust Contrast
t.write(result(:, :, j));
t.close();
The output image, as inspected by both MATLAB and ImageJ, is the correct size and has the correct metadata, but all values are zero.
Update:
MATLAB's documentation is somewhat sparse for the TIFF class, which itself is a wrapper for the LibTIFF library. The official TIFF Specification Version 6 denotes the full list of required fields for each TIF image type.
Upvotes: 0
Views: 981
Reputation: 10570
In the example of MATLAB documentation: Exporting to images there is one line which you don't have in your code:
tagstruct.RowsPerStrip = 16
So maybe missing RowsPerStrip
field of tagstruct
is the cause of the image of all zeros.
Upvotes: 1