Reputation: 31
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 !
Upvotes: 1
Views: 1736
Reputation: 11220
I thought I'd just add a note to @mark-setchell's excellent answer, but it came out too long, so I've made a separate one, sorry.
Your problem is that imagemagick (at least on current Ubuntu) saves pyramidal JPEG TIFFs as RGB rather than YCbCr, so they are huge. For example, wtc.jpg
is a 10,000 x 10,000 pixel JPEG image saved with the default Q75:
$ 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
You can see the compression type like this:
$ tiffinfo x-convert.tif | grep -i interp
Photometric Interpretation: RGB color
Perhaps there's some way to make it use YCbCr instead? I'm not sure how, unfortunately.
I would use libvips instead. It's more than 10x faster (on this laptop anyway), uses much less memory, and it enables YCbCr mode correctly, so you get much smaller files:
$ 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
If you set Q lower, you can get the size down more:
$ 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
Though I'd stick at the default Q75 myself.
Upvotes: 2
Reputation: 208077
I am not familiar with IIPImage server, so my thoughts may be inappropriate. If you store a tiled TIFF, you are storing multiple resolutions and all but the highest resolution is redundant - so could you maybe just store the highest resolution and generate the lower ones on demand?
The "PalaisDuLouvre.tif" image is 2MB as a tiled TIF:
ls -lhr PalaisDuLouvre.tif
-rw-r--r--@ 1 mark staff 1.9M 30 Mar 11:24 PalaisDuLouvre.tif
and it contains the same image at 6 different resolutions:
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
Yet, I can store it in better quality (90%) than your tiled TIFF like this:
convert PalaisDuLouvre.tif[0] -quality 90 fullsize.jpg
with size 554kB:
-rw-r--r-- 1 mark staff 554K 30 Mar 13:44 fullsize.jpg
and generate a tiled TIF the same as yours in under 1 second on demand with:
convert fullsize.jpg -define tiff:tile-geometry=256x256 -compress jpeg ptif:tiled.tif
Alternatively, you could use vips
to make your TIFF pyramid even faster. The following takes 0.2secs on my iMac, i.e. nearly 5x faster than ImageMagick:
vips tiffsave fullsize.jpg vips.tif --compression=jpeg --Q=45 --tile --tile-width=256 --tile-height=256 --pyramid
Upvotes: 1