Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chop image into tiles using VIPS command-line

I have a large Tiff image that I want to chop into 512x512 tiles and write to disk.

In the past I've used ImageMagick like so:

convert -crop 512x512 +repage image_in.tif image_out_%d.tif

But recently this hasn't been working, processes running out of memory, etc.

Is there a similar command in VIPS? I know there's a CLI but I can't find an example or useful explanation in the documentation, and I'm still trying to figure out the nip2 GUI thing. Any help appreciated. :)

like image 592
Nicholas McCarthy Avatar asked Dec 20 '22 21:12

Nicholas McCarthy


1 Answers

libvips has a operator which can do this for you very quickly. Try:

$ vips dzsave wtc.tif outdir --depth one --tile-size 512 --overlap 0 --suffix .tif

That's the DeepZoom writer making a depth 1 pyramid of tif tiles. Look in outdir_files/0 for the output tiles. There's a chapter in the docs talking about how to use dzsave.

It's a lot quicker than IM for me:

$ time convert -crop 512x512 +repage huge.tif x/image_out_%d.tif
real    0m5.623s
user    0m2.060s
sys     0m2.148s
$ time vips dzsave huge.tif x --depth one --tile-size 512 --overlap 0 --suffix .tif
real    0m1.643s
user    0m1.668s
sys     0m1.000s

Where huge.tif is a 10,000 by 10,000 pixel uncompressed RGB image. Plus it'll process any size image in only a small amount of memory.

like image 121
jcupitt Avatar answered Jan 02 '23 15:01

jcupitt