libvips / pyvips

python binding for libvips using cffi
MIT License
628 stars 49 forks source link

Load openslide (.svs) form buffer? #485

Closed Recontaminated closed 1 month ago

Recontaminated commented 1 month ago

Hello! I have an issue similar to the solution in #97 except I need to load these images from a remote source. I have a BytesIO Object and I am trying to load my 32k x 32k svs image via

        source = pyvips.Source.new_from_memory(file_stream.getvalue())
        image = pyvips.Image.openslideload_source(source,level=2,memory=True )

I'm using it following the example but it seems to expect a filename and gives me this error:

  File "/home/jeremy/Documents/GitHub/Fulgent/pathovision/goOpenSlideServer/server.py", line 407, in _get_dzg
    image = pyvips.Image.openslideload_source(source,level=2,memory=True,filename="lol.jpg")
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jeremy/miniconda3/envs/py3.11/lib/python3.11/site-packages/pyvips/vimage.py", line 256, in call_function
    return pyvips.Operation.call(name, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jeremy/miniconda3/envs/py3.11/lib/python3.11/site-packages/pyvips/voperation.py", line 288, in call
    raise Error('{0} does not support optional argument {1}'
pyvips.error.Error: openslideload_source does not support optional argument filename

I'm trying to create my own version of openslide's deepzoomgenerator except that it is able to load a svs file form a remote source. I'm pretty sure this is a really specific edge case but it would be amazing for any guidance on this.

What I'm trying to do is create a tileserver that can serve content in s3, caching the svs files in memory.

Cheers

jcupitt commented 1 month ago

Hi @Recontaminated,

I'm trying to create my own version of openslide's deepzoomgenerator except that it is able to load a svs file form a remote source.

Sorry, this isn't possible. openslide 3.4 only supports filesystem sources, so you'll need to download the whole image to local disc.

openslide 4.0 adds a VFS layer so you can use any filesystem-like backend (must support posix-like get dir, open file, seek, read, etc.), but libvips does not yet support this, and (thinking about it) I'm not sure if the opennslide VFS layer is exposed in the public openslide API.

Recontaminated commented 1 month ago

Hey @jcupitt!

In #97 you mention you can load like this

level = pyvips.Image.new_from_file(filename, level=2)

to skip resize, but the documentation doesn't mention the existance of a level keyword. Was this feature removed?

jcupitt commented 1 month ago

Hi again, could you post a new question in a new issue? Many different questions in one issue makes it hard for people to search.