TODO
- imwrite的局限
- 对于float, double数据类型,如何存储
- 不同的数据压缩方案
Matlab支持对多幅TIFF图像的写入(write),但是,不支持32位的操作。换句话说,如果运行下面的代码:
imwrite(uint32(data), 'test.tif');
那么程序会报错:
Error using writetif (line 92)
Writing uint32 image data to a TIFF file is not supported with IMWRITE. Use Tiff instead. Type "help Tiff" for more
information.
Error in imwrite (line 472)
feval(fmt_s.write, data, map, filename, paramPairs{:});
提示我们使用Tiff来实现。
(1) 对于单幅Tiff图像,例如data是一幅二维图像(50*60)
t = Tiff('test.tif', 'w');
t.setTag('ImageLength', 50);
t.setTag('ImageWidth', 60);
t.setTag('Photometric', Tiff.Photometric.MinIsBlack);
t.setTag('BitsPerSample', 32); % 32 bit
t.setTag('SamplesPerPixel', 1);
t.setTag('PlanarConfiguration', Tiff.PlanarConfiguration.Chunky);
t.write(data);
t.close;
(2) 对于写入多幅tiff图像,例如data是一个三维图像(5060100)
for j = 1:1:100 % 100层
if j == 1
t = Tiff('test.tif','w');
else
t = Tiff('test.tif', 'a');
end
t.setTag('ImageLength', 50);
t.setTag('ImageWidth', 60);
t.setTag('Photometric', Tiff.Photometric.MinIsBlack);
t.setTag('BitsPerSample', 32);
t.setTag('SamplesPerPixel', 1);
t.setTag('PlanarConfiguration', Tiff.PlanarConfiguration.Chunky);
t.write(data(:,:,j));
t.close;
end
相关链接
https://stackoverflow.com/questions/14003402/writing-an-image-with-floating-point-values