numpyopencvtiffvipsopenslide

How to scale up the 20x (.svs whole-slide-image) to 40x slides?


I have a whole-slide-images (.svs format) which are scanned at 20x. For my problem, I would like to upscale the slides to 40x along with the slide metadata. I tried it by the combination of the openslide, NumPy, cv2, and vips command. For a smaller size of slides, I can achieve this but for larger size slides I can't. Is there a straightforward way available to achieve this?

I followed following steps

  1. open slide and NumPy to read the slide.
  2. cv2 to create the png upscaled .png image.
  3. vips vips2tiff command to convert .png to .svs file.

Solution

  • I would just use libvips resize. For example:

    $ vipsheader CMU-1.svs 
    CMU-1.svs: 46000x32914 uchar, 4 bands, srgb, openslideload
    $ /usr/bin/time -f %M:%e vips resize CMU-1.svs x.tif[compression=jpeg,tile,pyramid] 2
    673804:80.56
    $ vipsheader x.tif
    x.tif: 92000x65828 uchar, 3 bands, srgb, tiffload
    

    80s and 680mb of memory to make x.tif, a tiled, pyramidal, jpeg-compressed TIFF. libvips can't write SVS files, but this will be pretty close. By default it'll do the upsize with a bicubic interpolator.

    In Python you'd use pyvips:

    import pyvips
    
    x = pyvips.Image.new_from_file("CMU-1.svs")
    x = x.resize(2)
    x.write_to_file("x.tif", compression="jpeg", tile=True, pyramid=True)