How can I write 32-bit floating point TIFs with NaNs?
25 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
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
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!