1

I'm actualy creating Tiled TIFF from jpeg files by using ImageMagick. My aim is to work with IIPImage server. I can generate easily files but my problem is that I have to deal with a large warehouse of images and it's crucial to optimize the space occupied by my TIFF files.

Thus, by using a compression of 45% (and tiles of 256x256) I obtain a acceptable quality and It's the maximum level of optimization I know. With that configuration, my TIFF files have a little more the same size as the original jpeg files. For exemple, if a jpeg weights 10Mo, the result TIFF weights 11.4Mo. It's good but not enought because if my initial warehouse weights 2To, I have to plan at least 4To for my project.

Thereby, I want to know if it exists a way for optimizing further the size of my TIFF files without losing more quality than 45%... By using ImageMagick or another tool.

For information, I'm using this command for generating TIFF.

convert <jpeg file> -quality 45 -depth 8 +profile '*' -define tiff:tile-geometry=256x256 -compress jpeg 'ptif:<tiff file>'

Thanks !

4

2 回答 2

2

我想我只是在@mark-setchell 的出色答案中添加一个注释,但它出现的时间太长了,所以我单独做了一个,抱歉。

您的问题是 imagemagick(至少在当前的 Ubuntu 上)将金字塔形 JPEG TIFF 保存为 RGB 而不是 YCbCr,因此它们很大。例如,wtc.jpg是使用默认 Q75 保存的 10,000 x 10,000 像素的 JPEG 图像:

$ time convert wtc.jpg -quality 45 -depth 8 +profile '*' -define tiff:tile-geometry=256x256 -compress jpeg 'ptif:x-convert.tif'
real    0m27.553s
user    1m10.903s
sys 0m1.129s
$ ls -l wtc.jpg x-convert.tif 
-rw-r--r-- 1 john john 15150881 Mar 16 08:55 wtc.jpg
-rw-r--r-- 1 john john 37346722 Mar 30 20:17 x-convert.tif

你可以看到这样的压缩类型:

$ tiffinfo x-convert.tif | grep -i interp
  Photometric Interpretation: RGB color

也许有一些方法可以让它使用 YCbCr 代替?不幸的是,我不确定如何。

我会改用libvips。它的速度提高了 10 倍以上(无论如何在这台笔记本电脑上),使用的内存更少,并且可以正确启用 YCbCr 模式,因此您可以获得更小的文件:

$ time vips tiffsave wtc.jpg x-vips.tif --compression=jpeg --tile --tile-width=256 --tile-height=256 --pyramid
real    0m2.180s
user    0m2.595s
sys 0m0.082s
$ ls -l x-vips.tif 
-rw-r--r-- 1 john john 21188074 Mar 30 20:27 x-vips.tif
$ tiffinfo x-vips.tif | grep -i interp
  Photometric Interpretation: YCbCr

如果将 Q 设置得较低,则可以进一步减小尺寸:

$ vips tiffsave wtc.jpg x-vips.tif --compression=jpeg --tile --tile-width=256 --tile-height=256 --pyramid --Q 45
$ ls -l x-vips.tif 
-rw-r--r-- 1 john john 12664900 Mar 30 22:01 x-vips.tif

虽然我自己会坚持使用默认的 Q75。

于 2018-03-30T21:12:23.253 回答
1

我对 IIPImage 服务器不熟悉,所以我的想法可能不恰当。如果您存储平铺的 TIFF,您将存储多个分辨率,并且除了最高分辨率之外的所有分辨率都是多余的 - 那么您是否可以只存储最高分辨率并按需生成较低的分辨率?

“PalaisDuLouvre.tif”图像是 2MB 的平铺 TIF:

ls -lhr PalaisDuLouvre.tif 
-rw-r--r--@ 1 mark  staff   1.9M 30 Mar 11:24 PalaisDuLouvre.tif

它包含 6 种不同分辨率的相同图像:

identify PalaisDuLouvre.tif
PalaisDuLouvre.tif[0] TIFF 4000x828 4000x828+0+0 8-bit sRGB 1.88014MiB 0.000u 0:00.000
PalaisDuLouvre.tif[1] TIFF 2000x414 2000x414+0+0 8-bit sRGB 1.88014MiB 0.000u 0:00.000
PalaisDuLouvre.tif[2] TIFF 1000x207 1000x207+0+0 8-bit sRGB 1.88014MiB 0.000u 0:00.000
PalaisDuLouvre.tif[3] TIFF 500x103 500x103+0+0 8-bit sRGB 1.88014MiB 0.000u 0:00.000
PalaisDuLouvre.tif[4] TIFF 250x51 250x51+0+0 8-bit sRGB 1.88014MiB 0.000u 0:00.000
PalaisDuLouvre.tif[5] TIFF 125x25 125x25+0+0 8-bit sRGB 1.88014MiB 0.000u 0:00.000

然而,我可以像这样以比平铺 TIFF 更好的质量 (90%) 存储它:

convert PalaisDuLouvre.tif[0] -quality 90 fullsize.jpg

大小为 554kB:

-rw-r--r--   1 mark  staff   554K 30 Mar 13:44 fullsize.jpg

并根据需要在 1 秒内生成与您相​​同的平铺 TIF:

convert fullsize.jpg -define tiff:tile-geometry=256x256 -compress jpeg ptif:tiled.tif

或者,您可以使用vips使您的 TIFF 金字塔更快。以下在我的 iMac 上需要 0.2 秒,即比ImageMagick快近 5 倍:

vips tiffsave fullsize.jpg vips.tif --compression=jpeg --Q=45 --tile --tile-width=256 --tile-height=256 --pyramid
于 2018-03-30T12:49:35.073 回答