Imagemagick jpeg压缩无法将某些TIFF转换为Pyramid TIFF,但并非全部

时间:2014-04-18 18:17:38

标签: image image-processing imagemagick tiff tile

我使用以下循环将大约250个.tif文件转换为平铺金字塔.tif文件,每个文件大约15到35 mb:

for i in *.tif; do convert $i -define tiff:tile-geometry=256x256 -compress jpeg 'ptif:tiled-'$i; done

这可能适用于超过一半的图像:我得到一个压缩的,平铺的.tif文件,大小约为原始文件的1/4。对于那些不起作用的,我得到的图像文件输出大概可能大约4,000字节,而-debug all似乎弹出的一个错误是Bogus input colorspace. "JPEGLib"。如果通过IIP图像服务器传输并且在图像查看器中无法打开,则不会显示这些图像。

我已将其本地化为-compress jpeg参数。如果我在没有压缩的情况下运行,或者像-compress LossLess JPEG那样无损压缩,它似乎可以工作,但是平铺图像(显然)比原始图像大,这是我想要避免的。

针对无法针对我获得的图片转换的图片运行tiffinfo

$ tiffinfo WH-001.tif
    TIFF Directory at offset 0x106842c (17204268)
      Image Width: 1735 Image Length: 2479
      Resolution: 72, 72 pixels/inch
      Bits/Sample: 8
      Compression Scheme: None
      Photometric Interpretation: RGB color
      Extra Samples: 1<unassoc-alpha>
      FillOrder: msb-to-lsb
      Orientation: row 0 top, col 0 lhs
      Samples/Pixel: 4
      Rows/Strip: 1
      Planar Configuration: single image plane
      Page Number: 0-1
      DocumentName: WH-001.tif

工作

$ tiffinfo WH-090.tif
    TIFFReadDirectory: Warning, Unknown field with tag 32934 (0x80a6) encountered.
    TIFF Directory at offset 0xd4 (212)
      Subfile Type: (0 = 0x0)
      Image Width: 2800 Image Length: 4160
      Resolution: 600, 600 pixels/inch
      Bits/Sample: 8
      Compression Scheme: None
      Photometric Interpretation: RGB color
      FillOrder: msb-to-lsb
      Orientation: row 0 top, col 0 lhs
      Samples/Pixel: 3
      Rows/Strip: 3
      Planar Configuration: single image plane
      Software: Oi/GFS, writer v00.06.02
      Tag 32934: 0
      ICC Profile: <present>, 3144 bytes

虽然我不知道怎么说出为什么这个被打破了,为什么另一个有效。

2 个答案:

答案 0 :(得分:1)

我会考虑在这里使用libvips而不是convert

在这款具有10000 x 10k像素JPG源的普通笔记本电脑上,我看到了:

$ /usr/bin/time -f %M:%e convert wtc.jpg -define tiff:tile-geometry=256x256 -compress jpeg ptif:im.tif
1628568:34.29

这是1.6gb的内存峰值和34s的经过时间。

通过libvips,我看到:

$ /usr/bin/time -f %M:%e vips tiffsave wtc.jpg vips.tif --tile --pyramid --compression jpeg
53148:1.95

53mb的内存和2s的经过时间。它的速度提高了15倍,所需内存减少了30倍。它也使金字塔变得更小:

$ ls -l vips.tif im.tif 
-rw-r--r-- 1 john john 60672180 Mar  7 23:12 im.tif
-rw-r--r-- 1 john john 21419592 Mar  7 23:13 vips.tif

convert未启用YCbCr模式,因此金字塔大3倍。它们应该可以在iipimage中正常工作。

libvips还将自动为您拉平透明度。

文档会遍历tiffsave的所有选项:

https://libvips.github.io/libvips/API/current/VipsForeignSave.html#vips-tiffsave

答案 1 :(得分:0)

首先,通过检查“其他图像查看器”是否可以打开,确保“已损坏的”实际上没有损坏。

其次,我同意你的怀疑,它与-compress jpeg选项有关。原因是您的“损坏”图像包含透明度(请参阅Extra Samples: 1<unassoc-alpha>行),JPEG格式不支持以透明度(alpha)存储图像。

有关从图像文件中删除透明度的信息,请参阅this other post

相关问题