【问题标题】:Matlab write image with floating point values?Matlab用浮点值写入图像?
【发布时间】:2012-11-26 11:29:32
【问题描述】:

我有一个.tif 图像,其中每个像素值(单通道)都是浮点数。无论如何用matlab(imread)读取它做一些操作并用浮点写回它?

如果我使用imwrite(I,'img.tif'),它将被转换为 8 位单通道 (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();

Imfinfo:

   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]

【问题讨论】:

  • 你能输出imfinfo(filename)吗?

标签: image matlab floating-point tiff


【解决方案1】:

如果您要做的是读取包含浮点数的 .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();

【讨论】:

  • 我还没有'treid那个sn-p...我问是因为我认为可能有一个更简单的方法
  • 如果我不知道输入图像是浮点数还是 0...255 怎么办?因为如果它在 0...255 我需要做一个 im2double() 而如果它是浮点我不需要做 im2double... 对吗?我该如何检查
  • @Perason:我在问题中添加了 imfinfo
  • 无论如何,这个 sn-p 运行良好。问题是我不知道哪个是输入图像统计信息。可以是 0...255 或浮点数
  • 无论如何,只要确保格式与您的浮点 tiff 显示的内容相匹配。
猜你喜欢
  • 2012-12-09
  • 1970-01-01
  • 2015-07-02
  • 1970-01-01
  • 2011-07-18
  • 2011-01-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多