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

조회 수: 14 (최근 30일)
Kevin Crosby
Kevin Crosby 2011년 5월 10일
댓글: Walter Roberson 2019년 5월 24일
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

채택된 답변

Walter Roberson
Walter Roberson 2011년 5월 10일
편집: Walter Roberson 2015년 2월 27일
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
Chris Volpe
Chris Volpe 2019년 5월 24일
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 2019년 5월 24일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by