libvips / pyvips

python binding for libvips using cffi
MIT License
649 stars 50 forks source link

Create svs file with image pyramid, label and macro in pyvips? #455

Open tuttelikz opened 9 months ago

tuttelikz commented 9 months ago

How write/create .svs image and add associated images, label and macro? Is it possible in pyvips?

jcupitt commented 9 months ago

Hi @tuttelikz,

SVS is not a standard TIFF format, so standard TIFF readers and writers can't handle it. pyvips uses the openslide library to read SVS, but there's no SVS writer.

You might be able to write it using a lower level library like tifffile, but it'd be quite a lot of work. Maybe a week's effort? The openslide website has some docs on the layout: https://openslide.org/formats/aperio/

If possible, I would use tiled jpeg pyramidal TIFF. This is very similar to SVS, but is a standard and can be read by most programs. For example:

image.tiffsave("x.tif", compression="jpeg", tile=True, pyramid=True)

It looks like DICOM WG26 will be generally replacing vendor formats like SVS, so you could also consider that.

tuttelikz commented 8 months ago

Hi @jcupitt,

Thanks for your reply and thanks for keeping this library 👍🏼

Yes, I have been experimenting with the mentioned tiffsave functionality up to now as suggested to save image pyramid.

The task I was trying to solve further, and wondered if pyvips can help for this case; Making a single tiff file: image pyramid as well as associated images (eg. macro, label or overview), so that QuPath can automatically detect it (openslide or bioformats) with a metadata (resolution, magnification). I attached image screenshot for illustration.

sample Source: https://openslide.cs.cmu.edu/download/openslide-testdata/Ventana/Ventana-1.bif

Based your response, it seems I should better check with tifffile (Dicom is not preferred for my particular case).

Actually, there is no principal difference for me, if it's SVS, Roche-Tiff, or other WSI format for TIF.

jcupitt commented 8 months ago

DICOM is the standard non-vendor format for WSI images, so that'd be the one to pick IMO.

QuPath uses OME TIFF, so you could try that. It's pretty simple -- a planar subifd TIFF pyramid, with some XML in the IMAGEDESCRIPTION tag with all the metadata.

I posted some sample pyvips code here:

https://forum.image.sc/t/writing-qupath-bio-formats-compatible-pyramidal-image-with-libvips/51223/14

tuttelikz commented 8 months ago

Thanks for the recommendation. I will check on OME-TIFF later this week.