Convert to .TIFF without compression
28 views (last 30 days)
Show older comments
I have a 240x200 double matrix with range 0-1. I want to export it as a .TIFF while preserving original values, but when I do, the values are re-scaled to integers [0-255]. It currently looks like this:
imwrite(image, filename, 'tiff', 'Compression', 'none');
How can I preserve the original values?
0 Comments
Accepted Answer
Udit06
on 28 Aug 2023
Hi Chris,
You can use the following code to save the image in the .tiff format without scaling. The code snippet uses the MATLAB’s Tiff object, you can refer https://www.mathworks.com/help/matlab/ref/tiff.html for more details.
% filename: the name with which you want to save the file
% image: 240*200 double matrix with range 0-1
t = Tiff(filename, 'w');
tagstruct.ImageLength = size(image, 1);
tagstruct.ImageWidth = size(image, 2);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.BitsPerSample = 64; % 64-bit floating-point
tagstruct.SamplesPerPixel = 1;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.SampleFormat = Tiff.SampleFormat.IEEEFP;
tagstruct.Compression = Tiff.Compression.None;
t.setTag(tagstruct);
t.write(image);
t.close();
I hope this helps.
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!