Skip to content
Advertisement

How to merge tiles obtained using openslide-python

I am trying to combine tiles in the correct order so they end up as the same whole slide image (.svs file).

The .svs file is read from a filepath according to the function beloew:

JavaScript

In the picture below I am trying the merge the tiles I got using openslide-python’s DeepZoom generator (see code snippet below)

JavaScript

This is how I split the .svs into its tiles:

JavaScript

The helper functions process_slide and process_tile_index are given below

JavaScript

The get_40x_zoom_level function description:

JavaScript

This is how I try to merge the tiles back to its whole slide image (not necessarily in .svs format but the same image):

JavaScript

Here is what the final output looks like out.png

Advertisement

Answer

libvips can do this merge and join for you. You can call it from pyvips, the Python binding.

To load an svs image and split it into tiles you can write:

JavaScript

And it’ll write my-deepzoom.dzi and a directory, my-deepzoom_files, containing all the tiles. There are a lot of parameters you can adjust, see the chapter in the docs:

https://libvips.github.io/libvips/API/current/Making-image-pyramids.md.html

It’s very fast and can make pyramids of any size on even modest hardware.

You can recombine tiles to form images with arrayjoin. You give it a list of images in row-major order and set across to the number of images per row. For example:

JavaScript

It’s very fast and can join extremely large arrays of images.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement