【问题标题】:Imagemagick jpeg compression failing to convert some TIFF to Pyramid TIFF, but not allImagemagick jpeg 压缩无法将某些 TIFF 转换为 Pyramid TIFF,但不是全部
【发布时间】:2014-04-18 18:17:37
【问题描述】:

我正在使用以下循环将大约 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

虽然我不知道如何判断为什么一个坏了,为什么另一个工作。

【问题讨论】:

    标签: image image-processing imagemagick tiff tile


    【解决方案1】:

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

    在这台带有 10k 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 内存和 34 秒运行时间的峰值。

    使用 libvips 我看到了:

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

    53mb 的内存和 2 秒的运行时间。它的速度提高了 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

    【讨论】:

      【解决方案2】:

      首先,通过检查它们是否能够在其他图像查看器中打开,确保“损坏的那些”实际上没有损坏。

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

      请参阅 this other post 以从图像文件中删除透明度。

      【讨论】:

        猜你喜欢
        • 2011-05-19
        • 1970-01-01
        • 1970-01-01
        • 2011-08-09
        • 1970-01-01
        • 1970-01-01
        • 2016-06-13
        • 1970-01-01
        • 2021-03-31
        相关资源
        最近更新 更多