Skip to content

Image loading - #17

Merged
siemdejong merged 16 commits into
computationalpathologygroup:mainfrom
siemdejong:image-loading
Jan 22, 2026
Merged

Image loading#17
siemdejong merged 16 commits into
computationalpathologygroup:mainfrom
siemdejong:image-loading

Conversation

@siemdejong

@siemdejong siemdejong commented Jan 16, 2026

Copy link
Copy Markdown
Contributor

fixes #3 #20

This PR changes the way the framework loads images. Images are loaded as part of the algorithm. The image loading strategy can be shared across multiple algorithms, but algorithms are not required to use it. An algorithm should adhere to the BaseSegmenter Protocol, but algorithms can use a predefined abstract base class if they require a numpy array (NumpySegmenter) or simply a path (PathSegmenter).

NumpySegmenters need to be initialized with mpp (among other things). This loads the image at that exact mpp. This relies on an unreleased PR to MONAI. The exact current commit sha that currently implements it is added to the dependencies. Ideally, this should be addressed later once Project-MONAI/MONAI#7574 is merged. Choosing specific mpp allows to better finetune the ideal hyperparameters for the algorithms and to circumvent the issue where images can different resolutions at level 0. Of course users can pick an mpp that is already in the pyramid, then no interpolation will be performed.

Segmenter.segment() requires to input a Path and output a geojson.FeatureCollection. This allows for multiple things:

  1. an easy user interface; you can always input one thing and can expect it to work (unless the parameters are suboptimal)
  2. the output is always the same which is up to the user how to use it
  3. a fair comparison between runtimes

Any issues with the environment are now fixed, albeit somewhat unsafe via

[tool.uv]
index-strategy = "unsafe-best-match"

uv sync --all-extras is able to solve the environment with this change. Especially useful for the large_image dependency of histomicstk.

@siemdejong siemdejong linked an issue Jan 21, 2026 that may be closed by this pull request
@siemdejong

siemdejong commented Jan 21, 2026

Copy link
Copy Markdown
Contributor Author

Below one single run of examples/unsupervised_benchmarking.py with an example tiff as explained in #19, so no CPGSegmenter result. With the changes introduced in this PR in place we can later tune the hyperparameters if necessary.

bg_subtractor_mog2_h500_v16_heatmap
image

entropy_masker_heatmap
image

fastsam_fastsam-x_heatmap
image

fesi_heatmap
image

grandqc_tissue_detection_mpp10_heatmap
image

hest_deeplabv3_default_mpp5_heatmap
image

histomicstk_saliency_heatmap
image

improved_fesi_heatmap
image

li_heatmap
image

morphological_disk3_heatmap
image

od_gmm_slide_heatmap
image

otsu_heatmap
image

watershed_mindist10_heatmap
image

yen_heatmap
image

@siemdejong siemdejong changed the title [WIP: DO NOT MERGE] Image loading Image loading Jan 21, 2026
@siemdejong

siemdejong commented Jan 21, 2026

Copy link
Copy Markdown
Contributor Author

I probably broke some other examples other than unsupervised_benchmark.py. They'd need to migrate to the new image loading requirements. If you want we can do that before merging.

@siemdejong
siemdejong marked this pull request as ready for review January 21, 2026 15:17
@siemdejong
siemdejong requested a review from polejowska January 21, 2026 15:17
@siemdejong

siemdejong commented Jan 22, 2026

Copy link
Copy Markdown
Contributor Author

I validated the workflow of adding a new algorithm. With this setup requires only a few lines and some import statements here and there.

https://github.com/RTLucassen/slidesegmenter
rtlucassen_slidesegmenter_heatmap

The model itself has a shift issue though, I don't think there's something we can do about it.

EDIT: well, maybe we can do something about it. It looks like it is more so a scaling issue. But haven't seen it with other algorithms. I can open an issue for that later.

@siemdejong

Copy link
Copy Markdown
Contributor Author

EDIT: well, maybe we can do something about it. It looks like it is more so a scaling issue. But haven't seen it with other algorithms. I can open an issue for that later.

this actually highlights a bug. With the self.reader.get_wsi_at_mpp() it gets an image at a specific mpp, unless a relative tolerance allowes an existing level. Then, mask_to_geojson(mask, self.min_area, scaling_factor=self.reader.get_mpp(wsi, 0)[0] / self.mpp) still uses the self.mpp that was requests, which is misaligned. Will fix.

@siemdejong

siemdejong commented Jan 22, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the bug by calculating the scaling factor using the model output. Ready to merge.

rtlucassen_slidesegmenter_heatmap
image

@siemdejong
siemdejong merged commit c431091 into computationalpathologygroup:main Jan 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Load image at specific mpp Optimal images loading strategy

2 participants