Skip to content
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

added spacing to surface distances calculations #6144

Conversation

gasperpodobnik
Copy link
Contributor

@gasperpodobnik gasperpodobnik commented Mar 14, 2023

Fixes #6137 .

Description

A user can now pass a spacing parameter to surface distance metrics (Hausdorff distance, surface distance, surface dice), so that correct results can be obtained for images with non-isotropic spacing (e.g. (0.5, 0.5, 2) mm).
If spacing is a sequence, it must be of length equal to the image dimensions; if a single number, this spacing is used for all axes. If None, spacing of unity is used. Defaults to Noneso that current behaviour is preserved.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

gasperpodobnik and others added 13 commits March 14, 2023 17:22
I, gasperp <gasper.podobnik@gmail.com>, hereby add my Signed-off-by to this commit: 2d449b4
I, gasperp <gasper.podobnik@gmail.com>, hereby add my Signed-off-by to this commit: 26dd22c
I, gasperp <gasper.podobnik@gmail.com>, hereby add my Signed-off-by to this commit: 753253c

Signed-off-by: gasperp <gasper.podobnik@gmail.com>
Signed-off-by: gasperp <gasper.podobnik@gmail.com>
I, gasperp <gasper.podobnik@gmail.com>, hereby add my Signed-off-by to this commit: 4b15604
I, gasperp <gasper.podobnik@gmail.com>, hereby add my Signed-off-by to this commit: 5d7bb44

Signed-off-by: gasperp <gasper.podobnik@gmail.com>
Signed-off-by: gasperp <gasper.podobnik@gmail.com>
@wyli
Copy link
Contributor

wyli commented Mar 21, 2023

thank you, could you please add a few test cases for example in this file: https://github.com/Project-MONAI/MONAI/blob/dev/tests/test_surface_distance.py

then I can edit the PR to address the mypy issues

@gasperpodobnik
Copy link
Contributor Author

gasperpodobnik commented Mar 23, 2023

Hey, I noticed that the typical usage of the metrics classes is to simply call them (i.e. metric_class(y_pred, y)). This means that a __call__() method that is inherited from the parent IterationMetric class is used. However, this method does not support additional arguments, so there is no way to pass the spacing argument to the _compute_tensor method of the original metric_class (e.g. SurfaceDistanceMetric).
I think the best solution would be to add a spacing argument to the __call__() method of parent classes or to implement a new class (e.g. CumulativeIterationDistanceMetric) that inherits from lower-level classes and supports the handling of the spacing argument. This could then be passed as a parent class to all user-level metrics classes (i.e. SurfaceDistanceMetric, HausdorffDistanceMetric, etc.) that require the spacing argument for the correct calculation of results.
Let me know what you think is the best way of doing it :)

@wyli
Copy link
Contributor

wyli commented Mar 25, 2023

thanks @gasperpodobnik, I think we can add **kwargs to here

self, y_pred: TensorOrList, y: TensorOrList | None = None

and
self, y_pred: TensorOrList, y: TensorOrList | None = None

for additional parameters, could you please help revise if you agree?

@gasperpodobnik
Copy link
Contributor Author

sure :)
Do you maybe know which tool was used to get the reference measurements of Hausdorff distance, surface distance, etc. for testing?

Signed-off-by: gasperp <gasper.podobnik@gmail.com>
Signed-off-by: gasperp <gasper.podobnik@gmail.com>
Signed-off-by: gasperp <gasper.podobnik@gmail.com>
Signed-off-by: gasperp <gasper.podobnik@gmail.com>
Signed-off-by: gasperp <gasper.podobnik@gmail.com>
Signed-off-by: gasperp <gasper.podobnik@gmail.com>
…7-add-spacing-to-surface-distance-metrics

Signed-off-by: gasperp <gasper.podobnik@gmail.com>
Signed-off-by: gasperp <gasper.podobnik@gmail.com>
Signed-off-by: gasperp <gasper.podobnik@gmail.com>
Signed-off-by: gasperp <gasper.podobnik@gmail.com>
Signed-off-by: gasperp <gasper.podobnik@gmail.com>
Signed-off-by: gasperp <gasper.podobnik@gmail.com>
gasperpodobnik and others added 4 commits April 12, 2023 09:46
Signed-off-by: gasperp <gasper.podobnik@gmail.com>
Signed-off-by: gasperp <gasper.podobnik@gmail.com>
@wyli
Copy link
Contributor

wyli commented Apr 12, 2023

/build

Copy link
Contributor

@wyli wyli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

many thanks, it looks good to me.

@wyli wyli enabled auto-merge (squash) April 12, 2023 17:15
@wyli wyli merged commit ef1285a into Project-MONAI:dev Apr 12, 2023
@gasperpodobnik gasperpodobnik deleted the 6137-add-spacing-to-surface-distance-metrics branch April 12, 2023 17:23
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.

Add spacing to surface distances calculations
2 participants