Resizing and cropping on demand
See original GitHub issueHi,
This is more a request for advice than issue, if you can help!
The use case is a UI that allows to load images and zoom in / span across the image. Images can be in different formats (JPG, PNG, TIFF), that can be say from KBs to 1-2GB.
The approach we are following at the moment is to differentiate between big and small images.
For small images, we might not use pyvips at all since it seems that the overhead kills the performance gain.
For big images: we are loading first a low resolution image which we create beforehand. Then upon zooming, we are loading the relevant region that needs zooming (or rather, a slightly larger and high resolution region than needed, to minimise the number of calls made to libvips). For this, we are currently doing something like:
image = pyvips.Image.new_from_file(filename, access='sequential') image = image.crop() out = image.resize() data = out.write_to_buffer('.jpg', Q=quality)
Some questions:
- Is this the most efficient way to approach the problem?
- Reading through other issues (https://github.com/libvips/pyvips/issues/26) and libvips documentation, I’m thinking that something like the below should instead be quite faster?
im = pyvips.Image.thumbnail(filename, ) im = im.crop() data = im.write_to_buffer('.jpg', Q=quality)
- Is it worth to have different approaches depending on the format of the image?
- would something like direct access to the relevant region of the image be more efficient? But I could not find much documentation on this
Thanks a lot
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
The 2s is for openslide images (up to about 300,000 x 300,000 pixels), it’d be quicker for more normal files.
I made a node binding for libvips:
https://github.com/libvips/node-vips
You could probably write the tile server in that. I did it as an exercise and I don’t know anything about node, so it might need a bit of fixing up. It’s only ~2,000 lines, so it should be easy to work on.
Thanks for the pointers @jcupitt !
It’s for a webapp (to be ran either in browser or in an Electron.JS wrapper) that should be able to run locally on Mac/Linux/Windows. We have a React.JS frontend - we need to make the zoom and span experience fast, the specific use case is images annotation for Computer Vision (I guess you must be getting a lot of traffic due to Deep Learning these days! 😃 )
We can’t really create tiles beforehand for all the pictures as that could eat up a lot of disk space.
Waiting ~2s per image when needing to zoom in is not ideal either I guess, but possibly that could work - it would come into play only for big images. We will do some tests on our end using your pointers, thanks!