0

I am using libvips to get pyramids of .ndpi images.

through this answer and searching the documentation I found this command

vips extract_area myimage.ndpi[level=0] mypyramid.dz 0 0 10000 10000

Which extracts a crop starting at 0 0 and size 10000 10000 to a dzi file.

The level parameter is the magnification, 0 is the highest.

The problem is that the ndpi has the following images inside:

  • myimage_macro.tif
  • myimage_map.tif
  • myimage_x0.15625_z0.tif
  • myimage_x0.625_z0.tif
  • myimage_x10_z0.tif
  • myimage_x2.5_z0.tif
  • myimage_x40_z0.tif

And vips is taking myimage_macro.tif while I need myimage_x40_z0.tif

There should be a parameter like level to choose which from the images inside the OpenSlide (ndpi) I want.

Some people ask. Why not extracting the tif and then running vips?

Well, because vips tells me this:

openslide2vips: opening slide: No such value: directory 0, tag 278

Which means that using ndpisplit to extract the tif is somehow not saving the metadata to allow vips to recognize the image

So I am in a bit of a pesky situation. I have enormous images and I need to extract a slightly less enourmous piece and then have its pyramid.

Please help me, right now I am basically coding it all my self and it works but it is EXTREMELY slow.

lesolorzanov
  • 3,536
  • 8
  • 35
  • 53

1 Answers1

0

I've written this as an answer, though it's not really an answer. It seemed too long as just a comment.

The libvips openslideload operation lets you pick an associated image to load. You can get a list of the associated images from the slide-associated-images metadata tag. For example:

$ vipsheader -f slide-associated-images 2013_09_20_29.ndpi 
macro
$ vipsheader -f slide-associated-images CMU-1.svs
label, macro, thumbnail

You then pick out an associated image with perhaps:

$ vips crop CMU-1.svs[associated=label] x.jpg 10 10 100 100

To get a small part of the label.

So ... check what associated images openslide reports for your slide. If you can get the one you need, pick that with the associated parameter. If the image you need is not listed, I would contact the openslide project, since they will need to add support.

You could also check the openslide command-line tools, they might perhaps offer more options.

jcupitt
  • 10,213
  • 2
  • 23
  • 39
  • Oh that looks fantastic, it was the "associated" keyword I was looking for. I will try it. In the meantime I already did a python script to do this for me but my DZI looks a bit weird in the smaller resolutions haha – lesolorzanov Nov 22 '18 at 10:34
  • Oh no, sadly it didn't work. I tried `vipsheader myimage.ndpi myimage.ndpi: 226176x90880 uchar, 4 bands, rgb, openslideload` and `vipsheader -f slide-associated-images : macro` then I did `vips crop myimage.ndpi[associated=macro] macrofromheader.dz 0 0 10000 10000` and it says extract_area: bad extract area – lesolorzanov Nov 22 '18 at 10:38
  • Also for crop since crop is an alias of extract_area. – lesolorzanov Nov 22 '18 at 10:41
  • Ok so now something worked and I am at a loss why but it is good. Thank you for helping me out! What I finally ran was `vips extract_area myimage.ndpi[level=0] mypyramid.dz[tile-size=1024] 0 0 20000 20000` (which was the same from my question), but now it loads the colors properly. The only difference is the tile-size property for the dzi. I wonder if it is a bug because at first it only gave me a weird greyscale image. – lesolorzanov Nov 22 '18 at 10:59
  • Oh huh how strange. `level=0` is the default, you shouldn't need that. If you can find a smallish image which shows the problem, please open an issue on the libvips bug tracker https://github.com/libvips/libvips/issues/new – jcupitt Nov 22 '18 at 11:45