How can I write 32-bit floating point TIFs with NaNs?

37 Ansichten (letzte 30 Tage)
Kevin Crosby
Kevin Crosby am 10 Mai 2011
Kommentiert: Walter Roberson am 24 Mai 2019
I'm able to use IMREAD to read 32-bit floating point TIFs with NaNs for dead pixels.
After this, I do an image rotation with IMTRANSFORM with 'FillValue' of NaN (IMROTATE only fills with zeros).
Now, I'd like to save 32-bit floating point TIFs with NaNs in tact for later.
How can I do this? I've tried IMWRITE and MULTIBANDWRITE, but they don't seem to work.
I'm using MATLAB 7.11.0 (R2010b).
Thanks,
Kevin Crosby

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 10 Mai 2011
Bearbeitet: Walter Roberson am 27 Feb. 2015
I suggest using the Tiff class and specifying RGB for the Photometric and specifying 32 bits per channel and writing single precision values.
This is based upon the assumption that you want the channel values themselves to be NaN, rather than setting the Alpha value to be NaN for the dead pixels.
  4 Kommentare
Chris Volpe
Chris Volpe am 24 Mai 2019
I've tried this, but it's converting my 32-bit float data to 8 BPP grayscale for some reason. My data is range data, specified in millimeters as a single precision float. I've tried both MinIsBlack and LinearRaw for the Photometric option, but no luck. Any thoughts?
Here's my code:
t = Tiff(fullfile(filepath, [basename '.tif']), 'w');
tagstruct.ImageLength = size(depthImage, 1);
tagstruct.ImageWidth = size(depthImage, 2);
tagstruct.Compression = Tiff.Compression.None;
tagstruct.SampleFormat = Tiff.SampleFormat.IEEEFP;
tagstruct.Photometric = Tiff.Photometric.LinearRaw;
tagstruct.BitsPerSample = 32;
tagstruct.SamplesPerPixel = 1;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
t.setTag(tagstruct);
t.write(single(depthImage));
t.close();
Walter Roberson
Walter Roberson am 24 Mai 2019
I just re-tested the code I posted at https://www.mathworks.com/matlabcentral/answers/307519-image-file-saved-using-tiff-library-tif-appear-white-in-explorer-and-paintbrush#answer_239772 and confirm that it creates single precision on my Mac in R2019a. The only difference I can see is the Photometric.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Images 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