pyvips icon indicating copy to clipboard operation
pyvips copied to clipboard

image resize: unsupported gap

Open Borda opened this issue 3 years ago • 7 comments

Hello, I have a question about a discrepancy between the docs and the actual package. I want to use image resize with sending optional gap as it is referred to in docs, but it crashes with an error...

Package: 2.2.0 (from conda) Docs: https://libvips.github.io/pyvips/vimage.html?highlight=resize#pyvips.Image.resize image Code:

img = pyvips.Image.new_from_file(img_path).resize(0.05, gap=2.0).numpy()

Output:

opt/conda/lib/python3.7/site-packages/pyvips/vimage.py in call_function(*args, **kwargs)
   1345         @_add_doc(name)
   1346         def call_function(*args, **kwargs):
-> 1347             return pyvips.Operation.call(name, self, *args, **kwargs)
   1348 
   1349         return call_function

/opt/conda/lib/python3.7/site-packages/pyvips/voperation.py in call(operation_name, *args, **kwargs)
    287                     name not in intro.optional_output):
    288                 raise Error('{0} does not support optional argument {1}'
--> 289                             .format(operation_name, name))
    290 
    291             value = kwargs[name]

Error: resize does not support optional argument gap

Borda avatar Jul 24 '22 07:07 Borda

Hi @Borda,

The gap param was added in 8.13 and the conda package hasn't updated yet.

Are you sure you need to use gap? It's mostly an internal feature.

jcupitt avatar Jul 24 '22 10:07 jcupitt

Well, I need to scale WSI images which are about 100kx100k to about 2kx2k within equate short time... Are you sure about the 8.13 on pip I see the latest 2.2.1 from last month: https://pypi.org/project/pyvips/#history

UPDATE: ok, I found the referred version... :) can you help me understand what the version pairing between libvips and its python wrappers is?

Borda avatar Jul 24 '22 12:07 Borda

FWIW, the gap param of vips_resize already defaults to 2.0, so there's no need to set it explicitly, see: https://github.com/libvips/libvips/blob/ffe13810fbc449403a5ac823f6b21b3c1e076695/libvips/resample/resize.c#L395

kleisauke avatar Jul 24 '22 12:07 kleisauke

The python wrapper is (largely) generated at runtime, so the API you get is the API of the underlying libvips binary. Just drop in the libvips.so for 8.13 and you should get the new API.

The thumbnail operation knows about the various WSI formats and will pick the fastest resize method for you. For example, on this seven year old laptop:

john@kiwi:~/pics/openslide$ vipsheader CMU-3.mrxs 
CMU-3.mrxs: 109240x220696 uchar, 4 bands, srgb, openslideload
john@kiwi:~/pics/openslide$ time vipsthumbnail CMU-3.mrxs --size 2000

real	0m0.875s
user	0m1.036s
sys	0m0.075s
john@kiwi:~/pics/openslide$ vipsheader tn_CMU-3.jpg 
tn_CMU-3.jpg: 990x2000 uchar, 3 bands, srgb, jpegload

Or in python:

image = pyvips.Image.thumbnail("CMU-3.mrxs", 2000)
image.write_to_file("thumb.jpg")

jcupitt avatar Jul 24 '22 13:07 jcupitt

Oh, conda is a bit different, sadly, it lives in its own tiny mad world. You might have to wait for the conda package to update.

jcupitt avatar Jul 24 '22 13:07 jcupitt

I commented on https://github.com/conda-forge/pyvips-feedstock/pull/24#issuecomment-1193322009 to mention that pyvips should be backward compatible with older libvipses. Hopefully they will update it to v2.2.1.

kleisauke avatar Jul 24 '22 13:07 kleisauke

FYI, just trying to install it for the Kaggle kernel, which is running Linux and python 3.7, but it seems it is not present in the registry... Do you think it'll take more time, or does the build configuration of 2.2.1 not cover the Kaggle specifics? https://www.kaggle.com/code/jirkaborovec/conda-pkg-pyvips-download-4-offline

Borda avatar Jul 25 '22 07:07 Borda