Convert to .TIFF without compression

28 vues (au cours des 30 derniers jours)
Chris Taylor
Chris Taylor le 21 Août 2023
Commenté : Chris Taylor le 29 Août 2023
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?

Réponse acceptée

Udit06
Udit06 le 28 Août 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.
  1 commentaire
Chris Taylor
Chris Taylor le 29 Août 2023
Hi,
That's great, thanks so much!
Chris

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by