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:
Solution 1:
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:
import pyvips
image = pyvips.Image.new_from_file("my-slide.svs")
image.dzsave("my-deepzoom")
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:
import pyvips
tiles = [pyvips.Image.new_from_file(f"{x}_{y}.jpeg", access="sequential")
for y inrange(height) for x inrange(width)]
image = pyvips.Image.arrayjoin(tiles, across=width)
image.write_to_file("huge.tif", compression="jpeg", tile=True)
It's very fast and can join extremely large arrays of images.
Post a Comment for "How To Merge Tiles Obtained Using Openslide-python"