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

39 次查看(过去 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

采纳的回答

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();

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by