Monday, 3 September 2012

making DeepZoom images with libvips

DeepZoom is a simple system for putting zoomable images into web pages. I put a demo page up here:

http://www.rollthepotato.net/~john/deepzoom/

All you need to do is convert your image to deepzoom format and paste a few lines of code into your page. Since 7.30.1, libvips has included a fast DeepZoom saver. Use it like this:
$ vips dzsave theo.jpg dz --overlap 12 --tile-size 94
This will create a directory called "dz_files" containing all the image tiles, and a file called "dz.dvi" containing the image metadata. Tile size and overlap are 256 and 1 by default. You can also set the image format for the tiles.

It runs quickly and doesn't need much memory. It streams the source image through the Deep Zoom writer, keeping just enough in memory to be able to write two lines of tiles. Memory use therefore scales with image width, not image size. It also uses a set of threads to write tiles in parallel, so it ought to get faster on many-core machines.

On my elderly desktop I see:
$ vips dzsave theo.jpg dz --vips-leak
memory: high-water mark 20.77 MB
real    0m1.480s
user    0m1.632s
sys     0m0.312s
For comparison, OpenZoom have a DeepZoom writer done in PIL:
$ time ./deepzoom.py theo.jpg
memory: peak RSS 150 MB
real    0m25.983s
user    0m25.014s
sys     0m0.368s
So vips is about 17 times faster and needs one seventh of the memory.

The differences are larger for larger images. On a 10,000 x 10,000 pixel image I see:
$ time vips dzsave wtc.jpg x --vips-leak
memory: high-water mark 32.36 MB
real    0m5.450s
user    0m6.364s
sys     0m0.952s
$ time ./deepzoom.py wtc.jpg
memory: peak RSS 600 MB
real    1m43.012s
user    1m41.598s
sys     0m0.828s
Now vips is about 20 times faster and needs one twentieth of the memory.

7 comments:

  1. I added some notes about arguments and how memory use and performance should scale.

    ReplyDelete
  2. git master libvips now supports Zoomify and Google maps formats as well. I made this Zoomify pyramid in 15 minutes on my laptop:

    http://www.rollthepotato.net/~john/zoomify/1-Defaults.htm

    That's processing from a jpeg2000 source, it'd be quicker from regular jpeg, or tiff.

    ReplyDelete
  3. does it possible to specify some flag to overwrite or ( better ), make missed parts from it

    ReplyDelete
  4. You can only remake the whole pyramid.

    I made a fastcgi tile server here that makes tiles on the fly directly from the original image:

    https://github.com/jcupitt/tilesrv

    but of course that's not suitable for high-traffic sites.

    ReplyDelete
  5. Hi John,

    What are the hardware specifications (CPU, RAM, etc.) for the "elderly desktop" that you used to run these benchmarks?

    Thanks.

    ReplyDelete
    Replies
    1. It was an HP workstation from 2006: 2 Opteron 254 processors at 2.7 GHz and 4GB of RAM.

      On my basic i5-3210m laptop, for a 10,000 x 10,000 pixel RGB JPEG I see:

      $ time vips dzsave wtc.jpg x
      real 0m2.320s
      user 0m5.259s
      sys 0m1.037s

      So about twice as fast. There's a more recent blog post on the pyramid builder here:

      http://libvips.blogspot.co.uk/2013/03/making-deepzoom-zoomify-and-google-maps.html

      Delete
    2. Thanks, John, for the very useful information!

      Delete