TIFF图生成和压缩:R与GIMP对比IrfanView与Photoshop文件大小 [英] TIFF plot generation and compression: R vs. GIMP vs. IrfanView vs. Photoshop file sizes

查看:483
本文介绍了TIFF图生成和压缩:R与GIMP对比IrfanView与Photoshop文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成了一些高分辨率的出版质量图,例如

I generated some high resolution publication quality plots for example

library(plot3D)
Volcano<-volcano
zf=10 #zoom factor
tiff("Volcano.tif", width=1800*zf, height=900*zf, res=175*zf, compression="lzw")
image2D(z = Volcano, clab = "height, m",colkey = list(dist = -0.20, shift = 0.15,side = 3, length = 0.5, width = 0.5,cex.clab = 1.2, col.clab = "white", line.clab = 2,col.axis = "white", col.ticks = "white", cex.axis = 0.8))
dev.off()

文件为22 MB。

现在我用GIMP和打开文件而不做任何其他事情我将其导出为Volcano gimp.tif(不要更改分辨率) ,或做任何其他事情)。 GIMP生成一个1.9 MB的文件(Volcano gimp.tif)。

Now I open the file with GIMP and without doing anything else I export it as "Volcano gimp.tif" (don't change resolution, or do anything else). GIMP generates a file ("Volcano gimp.tif") that is 1.9 MB.

imagemagick 报告类似图像统计:

$ identify Volcano.tif
Volcano.tif TIFF 18000x9000 18000x9000+0+0 8-bit DirectClass 22.37MB 0.000u 0:00.000
$ identify "Volcano gimp.tif"
Volcano gimp.tif TIFF 18000x9000 18000x9000+0+0 8-bit DirectClass 1.89MB 0.000u 0:00.000

即使使用识别-verbose 这两个文件似乎相似。

even using identify -verbose the 2 files appear to be similar.

这些文件有什么区别?为什么他们的文件大小如此不同?

What is the difference between these files? Why do they have so different file sizes?

更新:好的,事情变得越来越疯狂了。我用IrfanView做了同样的事情,我得到了不同的文件大小。初始文件是从 R 生成的 Volcano.tif ,其中 compression =lzw。检查 Volcano irfan.tif Volcano gimp.tif 的大小不同但所有其他统计数据都相同。内存占用,DPI,颜色,分辨率相同。磁盘大小不同。

UPDATE: OK, things are getting crazier. I did the same thing with IrfanView and I get different file sizes. The initial file is the Volcano.tif generated from R with compression="lzw". Check how Volcano irfan.tif and Volcano gimp.tif differ in size but all other stats are the same. Memory footprint, DPI, Colors, Resolution is identical. Disk size is different.

更新2: Adob​​e Photoshop将文件保存至2.6 MB

UPDATE 2: Adobe Photoshop saves the file down to 2.6 MB

WinRar报告原始R生成的TIFF是高度可压缩的(从22MB - > 3.6MB)

WinRar reports that the original R generated TIFF is highly compressible (from 22MB ->3.6MB)

更新3:此问题可能类似于蒙太奇/加入2张幻灯片中的2张TIFF图像1行瓷砖不会丢失质量

更新4:可以在此处找到R生成的TIFF文件 http://ge.tt/7ZvRd4C1/v/0?c

UPDATE 4: The R generated TIFF file can be found here http://ge.tt/7ZvRd4C1/v/0?c

推荐答案

显然R使用的TIFF LZW压缩器没有使用impo rtant选项(TIFF预测器),它导致一个非常大的文件。当数据压缩能够识别数据中的对称性/冗余时,数据压缩效果最佳。在这种情况下,图像数据由包含红色,绿色和蓝色8位值的24位(3字节)像素组成。标准LZW压缩查看重复模式的字节流。如果它将彩色图像简单地看作字节流,它将看到重复的3字节模式,而不是重复恒定颜色的模式。对数据启用TIFF预测器会导致差分滤波器存储每个像素与其邻居的增量。如果相邻像素是相同的颜色,它将存储0。一个长0的字符串压缩比重复至少3个字节长的非零的模式要好得多。

Apparently the TIFF LZW compressor used by R is not making use of an important option (the TIFF predictor) which is leading to an extremely large file. Data compression works best when it can recognize symmetries/redundancies in the data. In this case, the image data is composed of 24-bit (3-byte) pixels containing red, green and blue 8-bit values. Standard LZW compression looks at a stream of bytes for repeating patterns. If it looks at the color image simply as a stream of bytes, it will see repeating patterns of 3-bytes instead of repeating patterns of constant color. Enabling the TIFF predictor on the data causes a differencing filter to store the delta of each pixel with its neighbor. If the neighboring pixels are the same color, it will store 0's. A long string of 0's compresses much better than repeating patterns of non-zeros which are at least 3 bytes long.

这是一个如何在6像素上工作的示例线。编码时,预测器从右边缘开始,并在每条扫描线上向左移动:

Here is an example of how it works on a 6 pixel line. When encoding, the predictor starts from the right edge and works left for each scan line:

Original data:
2A 50 40 2A 50 40 2A 50 40 2A 50 40 2A 50 40 2A 50 40 (6 pixels of the same color)

After horizontal differencing (TIFF predictor):
2A 50 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

The data is much more compressible after the predictor since long runs of the same value (0x00) are easier for LZW to compress.

结论:这应该作为R压缩代码的所有者提交的错误,因为使用LZW没有预测器的全彩色图像会产生不良结果。与此同时,需要一种解决方法来更有效地压缩它。

Conclusion: This should be filed as a bug against the owner of the R compression code since using LZW on full color images without the predictor produces poor results. In the mean time, a workaround is needed to compress it more efficiently.

这篇关于TIFF图生成和压缩:R与GIMP对比IrfanView与Photoshop文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆