我使用下面的循环将大约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 Image Server传输,则不会显示,也不会在图像查看器中打开。
我已经将其本地化为可能的-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
虽然我不确定如何判断为什么一个坏了,为什么另一个工作。
发布于 2019-03-07 23:28:13
我会考虑在这里使用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.6 So的内存和34秒的运行时间。
对于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
发布于 2015-03-02 18:23:23
首先,通过检查它们是否能够在其他图像查看器中打开,确保“损坏的图片”实际上没有损坏。
其次,我同意您的怀疑,即它与-compress jpeg
选项有关。原因是您的“损坏”图像包含透明度(请参阅JPEG行),而Extra Samples: 1<unassoc-alpha>
格式不支持存储具有透明度(alpha)的图像。
有关从图像文件中删除透明度的信息,请参阅this other post。
https://stackoverflow.com/questions/23159794
复制相似问题