Convert to .TIFF without compression

24 Ansichten (letzte 30 Tage)
Chris Taylor
Chris Taylor am 21 Aug. 2023
Kommentiert: Chris Taylor am 29 Aug. 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?

Akzeptierte Antwort

Udit06
Udit06 am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by