-1

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.
Nick ODell
  • 15,465
  • 3
  • 32
  • 66

1 Answers1

0

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)
jcupitt
  • 10,213
  • 2
  • 23
  • 39
  • I tried to install pyvips using [pyvips](https://pypi.org/project/pyvips/) but i got following error `AttributeError: function/symbol 'vips_object_get_args' not found in library 'libvips.so.42': /usr/local/lib/libvips.so.42: undefined symbol: vips_object_get_args` and when tried to use below command `vips resize CMU-1.svs x.tif[compression=jpeg,tile,pyramid] 2` I got the following error `no matches found: x.tif[compression=jpeg,tile,pyramid] ` – Murali Selvaraj Aug 18 '21 at 14:09
  • You have a very old libvips, perhaps 8.4? I'd update it. – jcupitt Aug 18 '21 at 19:17
  • My system version: `Ubuntu 16.04.3 LTS` and vips version is: `$ vips -v vips-8.7.0-Wed Jun 27 7:24:46 UTC 2018 $ vips --vips-version libvips 8.7.0-Wed Jun 27 7:24:46 UTC 2018 ` I tried to upgrade the vips using the below command but still, I get the same older version. `$ sudo apt-get update $ sudo apt-get remove --auto-remove libvips libvips-dev $ sudo apt-get install libvips libvips-dev ` – Murali Selvaraj Aug 19 '21 at 07:21
  • Your libvips is in `/usr/local`, it's not the one from ubuntu, it's a version you compiled yourself back in 2018. You need to update it. – jcupitt Aug 19 '21 at 09:44
  • The "no matches found" error is from your shell -- you are using something unusual. Try putting quotes around the argument, eg. `vips resize CMU-1.svs "x.tif[compression=jpeg,tile,pyramid]" 2`. – jcupitt Aug 19 '21 at 09:45
  • Thank you very much @jcupitt. I was able to recompile it. Almost, I got what I wanted except the file format `.svs`. Are there any methods available to convert the slides from `.tif to .svs`? – Murali Selvaraj Aug 19 '21 at 12:10
  • There are some SVS docs here: https://openslide.org/formats/aperio --- you just need to set `IMAGEDESCRIPTION`. – jcupitt Aug 19 '21 at 13:58