pathml
pathml copied to clipboard
Retrieve tiles on universal and specific magnification
For a cohort, when users would like to tile the slides on one or several specific magnifications, it is very possible that the exsiting codes output the same size tiles with different magnifications becasue level0 may return 20x or 40x tiles and level_downsamples are slide specific.
For example. I would like to tile the dataset on '10x' and '20x' with tile size of 256*256. Slide A (level0: 40x; level1:10x) Slide B (level0: 20x; level1: 5x)
Solution 1: Add an argument of magnification that can take a list where user can choose from ['40x','20x','10x','5x','2.5x'], we can set the default as None so that this argument will not impact the codes we already have now. Then we can add codes to look for the best level for each slide to query as well as whether we need to resize the tile. For slide A, we need to get level0 of 512512 tiles and resize to 256256 and level1 with size of 256256. For slide B, we need to get level0 with size of 512512 and 256256 then resize 512512 one into 256*256. The drawback is it requires slides to be Aperio.
sample codes are :
slide = openslide.open_slide(svspath)
m=round(float(slide.properties[‘aperio.MPP’]), 2)//0.25
level0=int(40/m)
bestlevel=0
for i in range(slide.level_count):
if round(level0/ slide.level_downsamples[i], 1) // 2.5 > 0:
bestlevel = i
rescale_factor=round(level0 / slide.level_downsamples[bestlevel],1)/2.5
Thanks Karen, this is a great suggestion!!
Right now, SlideDataset.run()
takes a single level
keyword argument which is passed to SlideData.run()
for each slide in the dataset. But that assumes homogenous levels, i.e. we want to pull tiles from the same level for each slide.
We could definitely make this more flexible to accomodate datasets of slides with different magnifications at each level.
Maybe a good solution would be to add a feature so that the level
argument in SlideDataset.run()
can take a list?
Then the user would be responsible for creating that list of levels for each slide in their dataset.
That way, it’s general so it won’t break for non-aperio images, but will still support nonhomogenous levels
''Maybe a good solution would be to add a feature so that the level argument in SlideDataset.run() can take a list? Then the user would be responsible for creating that list of levels for each slide in their dataset.''
I think this would work. But to get the level list users still need openslide. Maybe we can add a side function to generate this list, even it only works for Aperio?
Here's an idea:
Pass level 1 magnification as an argument when initializing a SlideData object with OpenSlide backend. Or, if the argument is not passed, we can try to infer it by looking at the metadata (although in some cases there may not be metadata; maybe raise an error in that case).
When generating tiles or running a preprocessing pipeline, the user can then specify a magnification, and since we know the level 1 magnification we can compute any smaller magnification by a combination of retrieving from a higher level and downsampling.
wsi = SlideData("path/to/slide.svs", backend = "openslide", magnification = 40)
wsi.run(pipeline, magnification = 10) # downsample to get 10x
magnification arguments would be ignored if the backend is not openslide
This sounds good to me. Just to confirm that you meant level 0 right?
Yes I meant level 0!
Do you want to take the lead on adding this feature, @Karenxzr ?
Hi,
I am trying to find whether I can get tiles at different magnifications from my H&E WSI. Searching for magnification in the docs, was not successful. Is this PR meant to integrate tiling at different magnifications from a WSI?
More specifically, if I need tiles at 5x from a WSI that was generated at 40x, is that possible?