Matlab:如何以透明度保存TIFF或无压缩的PNG



我必须在 Matlab 中处理大量图像并将结果保存到具有透明度的图像文件中。但是 PNG 压缩对我来说花费了太多时间。如何在不压缩的情况下保存 PNG 或具有透明度的 TIFF?还有其他方法可以在不压缩和透明的情况下保存图像吗?

这是我在这里的第一个问题,如果有任何错误,对不起我的英语不好和错误的问题风格。

使用 Matlab 中的 TIFF 类,您可以编写具有透明度的 TIFF:

%# create a synthetic RGBA image
ch = checkerboard(100);
rgba = repmat(ch,[1,1,4]);
rgba(:,:,4) = rgba(:,:,4)==0;
rgba = uint8(round(rgba*255));
%# create a tiff object
tob = Tiff('test.tif','w');
%# you need to set Photometric before Compression
tob.setTag('Photometric',Tiff.Photometric.RGB)
tob.setTag('Compression',Tiff.Compression.None)
%# tell the program that channel 4 is alpha
tob.setTag('ExtraSamples',Tiff.ExtraSamples.AssociatedAlpha)
%# set additional tags (you may want to use the structure
%# version of this for convenience)
tob.setTag('ImageLength',size(ch,1));
tob.setTag('ImageWidth',size(ch,2));
tob.setTag('BitsPerSample',8);
tob.setTag('RowsPerStrip',16);
tob.setTag('PlanarConfiguration',Tiff.PlanarConfiguration.Chunky);
tob.setTag('Software','MATLAB')
tob.setTag('SamplesPerPixel',4);
%# write and close the file
tob.write(rgba)
tob.close
%# open in Photoshop - see transparency!

Matlab 的imwrite没有 PNG 压缩级别的参数。 如果是这样,您可以将其设置为零而不压缩。 虽然对于TIFF,它确实有一个none选项Compression,但没有阿尔法通道。 您可以使用 Alpha 通道写入旧的太阳光栅格 (RAS) 格式,而无需压缩。 虽然没有人可能能够阅读它。

"PNG 没有未压缩的变体。仅使用未压缩的放气块就可以存储未压缩的数据"

未压缩的 deflate 块使用 5 个字节的标头 + 每个块最多 65535 字节的未压缩数据。

http://www.w3.org/TR/PNG-Rationale.html

最新更新