image - Matlab 用浮点值写图像?

标签 image matlab floating-point tiff

我有一个 .tif 图像,其中每个像素值(单 channel )都是 float 。有没有办法用 matlab (imread) 读取它做一些操作并以 float 写回?

如果我执行 imwrite(I,'img.tif') 它会转换为 8 位单 channel (0...255)

我只在 mathworks 上找到这个示例:

info = imfinfo(filename); 
t = Tiff(filename, 'w'); 
tagstruct.ImageLength = size(timg, 1); 
tagstruct.ImageWidth = size(timg, 2); 
tagstruct.Compression = Tiff.Compression.None; 
tagstruct.SampleFormat = Tiff.SampleFormat.IEEEFP; 
tagstruct.Photometric = Tiff.Photometric.MinIsBlack; 
tagstruct.BitsPerSample = info.BitsPerSample; % 32; 
tagstruct.SamplesPerPixel = info.SamplesPerPixel; % 1; 
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky; 
t.setTag(tagstruct); 
t.write(timg); 
t.close();

导入信息:

   info = 

                 Filename: [1x110 char]
              FileModDate: '04-dic-2012 12:02:07'
                 FileSize: 45720930
                   Format: 'tif'
            FormatVersion: []
                    Width: 2724
                   Height: 4193
                 BitDepth: 32
                ColorType: 'grayscale'
          FormatSignature: [73 73 42 0]
                ByteOrder: 'little-endian'
           NewSubFileType: 0
            BitsPerSample: 32
              Compression: 'Uncompressed'
PhotometricInterpretation: 'BlackIsZero'
             StripOffsets: [4193x1 double]
          SamplesPerPixel: 1
             RowsPerStrip: 1
          StripByteCounts: [4193x1 double]
              XResolution: 100
              YResolution: 100
           ResolutionUnit: 'None'
                 Colormap: []
      PlanarConfiguration: 'Chunky'
                TileWidth: []
               TileLength: []
              TileOffsets: []
           TileByteCounts: []
              Orientation: 1
                FillOrder: 1
         GrayResponseUnit: 0.0100
           MaxSampleValue: 4.2950e+09
           MinSampleValue: 0
             Thresholding: 1
                   Offset: 45720696
             SampleFormat: 'IEEE floating point'
       ModelPixelScaleTag: [3x1 double]
         ModelTiepointTag: [6x1 double]
       GeoKeyDirectoryTag: [52x1 double]
       GeoDoubleParamsTag: [3x1 double]

最佳答案

如果您想做的是读取包含 float 的 .tif,对其进行操作,然后再次将其写出,您的代码示例应该运行良好。只需添加读取的文件和图像处理,它应该工作得很好。

img = imread(in_filename)
timg = 2*timg;
info = imfinfo(in_filename); 

t = Tiff(out_filename, 'w'); 
tagstruct.ImageLength = size(timg, 1); 
tagstruct.ImageWidth = size(timg, 2); 
tagstruct.Compression = Tiff.Compression.None; 
tagstruct.SampleFormat = Tiff.SampleFormat.IEEEFP; 
tagstruct.Photometric = Tiff.Photometric.MinIsBlack; 
tagstruct.BitsPerSample = info.BitsPerSample; % 32; 
tagstruct.SamplesPerPixel = info.SamplesPerPixel; % 1; 
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky; 
t.setTag(tagstruct); 
t.write(timg); 
t.close();

关于image - Matlab 用浮点值写图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13777444/

相关文章:

javascript - JavaScript 中的精确浮点运算

c++ - 使用 C++,有没有办法检测编译器/系统是否将 floats/doubles 非规范化为 "normalized"?

javascript - 慢慢移动图片

c# - 生成条码时修复 "Generic error occurred in GDI+"

image - 所有 App Engine 图像服务 get_serving_url() URI 选项的列表

matlab - 在 Matlab 中调用具有不同数量参数的函数

java - 使用 Java 迭代所有浮点值

android - 如何在 Android 的 ListView 中延迟加载图像

path - MATLAB:将当前文件夹设置为脚本位置

matlab - 模式识别中绘图的相关问题(第1部分)