-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Limit bounds #146
Limit bounds #146
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks fine.
but i'm not seeing any tests. shouldn't we try to add tests to new functionalities?
many changes to the polygon functionality that seem unrelated to this PR and issue though.
So when the bounds are available (to my knowledge only with latest software of 3dhistech p1000 scanners), we likely want to use these bounds for any further processing. We have multiple use-cases for
I think that generally these
an explicit ROI "annotation" can be generated with e.g. the The current implementation allows to create a tiled dataset from the bounds, and if one already has a tissue mask this can be combined with it (either as a bounding box around the tissue mask, or by just passing the tissue mask), but it is not yet possible to compute a tissue mask within the bounds without additional custom steps. So likely we want to add this to Line 214 in 4395e75
SlideImage at mpp=32 so that it can be passed into the TiledROIsSlideImageDataset instantiation.
I think any other pre- or postprocessing steps with a slide with bounds will need to be implemented by the user. |
…t ((x1,y1),(x2,y2))
…imagedataset.from_standard_tiling
After discussing with @jonasteuwen , we decided that this feature is intended to give the user easy access to the bounds, and will be added automatically to For now, due to #151 this feature can not be used with I ran the following "test": from functools import partial
from dlup.data.dataset import TiledROIsSlideImageDataset
from dlup.experimental_backends import ImageBackend
from dlup import SlideImage
from pathlib import Path
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
from PIL import ImageDraw
def main():
mrxs_glob = "*/*/*.mrxs"
MRXS_ROOT_FOLDER = "" # */*/*.mrxs
TCGA_ROOT_FOLDER = "" # */*.svs
matador_paths = [path for path in Path(MRXS_ROOT_FOLDER).glob(mrxs_glob)][:5]
tcga_paths = [path for path in Path(TCGA_ROOT_FOLDER).glob('*/*.svs')][:5]
for slide_path in mrxs_paths + tcga_paths:
print(f"============================\n Slide: {slide_path.stem}")
for backend in [ImageBackend.OPENSLIDE, ImageBackend.PYVIPS]:
# ImageBackend.AUTODETECT fails
# ImageBackend.TIFFILE fails because we're not reading TIFFILEs.
print(f"-------\n Using backend: {backend}")
slide = SlideImage.from_file_path(slide_path, backend=backend)
print(f"Slide bounds: {slide.slide_bounds}")
print(f"Full slide size: {slide.size}")
ds = partial(TiledROIsSlideImageDataset.from_standard_tiling, path=slide_path, mpp=100, tile_size=(10, 10), tile_overlap=(0, 0), backend=backend)
ds_limit_bounds = ds(limit_bounds=True)
ds_no_limit_bounds = ds(limit_bounds=False)
print(f"Len of tiled dataset without limit bounds: {len(ds_no_limit_bounds)}")
print(f"Len of tiled dataset with limit bounds: {len(ds_limit_bounds)}")
scaled_region_view = slide.get_scaled_view(slide.get_scaling(100))
for limit_bounds in [True, False]:
ds2 = ds(limit_bounds=limit_bounds)
background = Image.new("RGBA", tuple(scaled_region_view.size), (255, 255, 255, 255))
for d in ds2:
tile = d["image"]
coords = np.array(d["coordinates"])
box = tuple(np.array((*coords, *(coords + 10))).astype(int))
background.paste(tile, box)
draw = ImageDraw.Draw(background)
draw.rectangle(box, outline="red")
background.save(f"{limit_bounds}_{str(backend).replace('.', '')}_{str(slide_path.stem).replace(' ', '')}.png")
if __name__ == "__main__":
main() Which gives the following output, where we see that it works for both Images are not uploaded here since we do not have access to open-source mrxs files at the moment.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the tests shown above I believe that the current implementation works as expected.
Thanks for the test. I don't think we can add it as such in dlup as it requires access to data. Ideally we do this with a 'mock'. |
If the image provides bounds for the image region, these were currently not processed. Adding
limit_bounds
to the constructor of the dataset will do this.