我需要在Matlab中处理大量图像,并将结果保存为具有透明度的图像文件。但PNG压缩对我来说时间太长了。如何保存没有压缩或具有透明度的TIFF格式的PNG?还有其他方法可以保存不带压缩和透明度的图像吗?
这是我在这里的第一个问题,如果问题中有任何错误,请原谅我的糟糕英语和错误的提问方式。
我需要在Matlab中处理大量图像,并将结果保存为具有透明度的图像文件。但PNG压缩对我来说时间太长了。如何保存没有压缩或具有透明度的TIFF格式的PNG?还有其他方法可以保存不带压缩和透明度的图像吗?
这是我在这里的第一个问题,如果问题中有任何错误,请原谅我的糟糕英语和错误的提问方式。
%# 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,它确实具有Compression
的none
选项,但没有alpha通道。您可以将其写入带有alpha通道且不压缩的旧Sun Raster(RAS)格式中。尽管很可能没有任何东西能够读取它。
"PNG没有未压缩的变种。通过仅使用未压缩的deflate块,可以存储未压缩数据"
未压缩的deflate块使用一个5字节的头部+每个块最多65535字节的未压缩数据。