0

I am using the following loop convert about 250 .tif files to tiled pyramid .tif file, each file is about 15 to 35 mb:

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

This is working for probably a little over half of the images: I get a compressed, tiled .tif file at about 1/4 the size of the original. For the ones that aren't working, I am getting an image file outputted that's probably about 4,000 bytes large and the one error that seems to pop with -debug all is Bogus input colorspace. "JPEGLib". These images do not appear if piped through IIP Image Server and won't open in an image viewer.

I have localized it to perhaps the -compress jpeg argument. If I run without compression, or a lossless compression like -compress LossLess JPEG, it appears to work, but the tiled images are (obviously) larger than the original, which is what I am trying to avoid.

running tiffinfo against an image that doesn't convert against an image that does I get:

Broken

$ 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

Working

$ 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

Though I am not sure how to tell why the one is broken and why the other one works.

Community
  • 1
  • 1
roy
  • 3,706
  • 6
  • 30
  • 53

2 Answers2

1

I would consider using libvips instead of convert here.

On this modest laptop with a 10k x 10k pixel JPG source, I see:

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

So that's a peak of 1.6gb of memory and 34s of elapsed time.

With libvips I see:

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

53mb of memory and 2s of elapsed time. It's 15x faster and needs 30x less memory. It makes smaller pyramids too:

$ 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 does not enable YCbCr mode, so the pyramids are 3x larger. They should work fine in iipimage.

libvips will also flatten out transparency for you automatically.

The docs run through all the options for tiffsave:

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

jcupitt
  • 10,213
  • 2
  • 23
  • 39
0

First, make sure the "broken ones" are actually not-broken by checking they are able to open in other image viewers.

Secondly, I agree with your suspicion that it has to do with the -compress jpeg option. The reason is that your "broken" images contain transparency (see the Extra Samples: 1<unassoc-alpha> line), and the JPEG format does not support storing the image with transparency (alpha).

See this other post for removing transparency from an image file.

Community
  • 1
  • 1
rwong
  • 6,062
  • 1
  • 23
  • 51