Matlab:如何保存透明的 TIFF 或不压缩的 PNG?

标签 matlab compression png transparency tiff

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

这是我的第一个问题,如果有任何错误,请原谅我的英语不好和问题风格错误。

最佳答案

使用 TIFF在 Matlab 类中,您可以透明地编写 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:如何保存透明的 TIFF 或不压缩的 PNG?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13660108/

相关文章:

.net - 减少.NET中的PNG文件大小

linux - 如何告诉 mex 链接到/usr/lib 中的 libstdc++.so.6 而不是 MATLAB 目录中的那个?

matlab - 在噪声信号中找到模型函数的稳健拟合

c - 使用 C : how to read cell-structure properly 读取 .mat 文件

java - 尝试编写一个可以使用 yovenny/VideoCompress 将视频压缩为小尺寸的代码

java - 使用 Java 或 Python 将 8 位(16 色调色板)PNG 转换为适当的 4 位(16 色调色板)?

matlab - 函数之外的 nargin 是什么?

linux - 如何在 linux 中查看 Hive orc 文件的内容

java - 如何将整数数组转换为 InputStream?

用于更快加载图像的 iOS Swift 技巧