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

Implementation of the Modified Hausdorff Distance (MHD) metric #5581

Merged
merged 18 commits into from Jan 6, 2022

Conversation

robinthibaut
Copy link
Contributor

Description

Greetings,

In the file skimage/metrics/set metric.py, I included the Modified Hausdorff Distance function. This brilliant library, I believe, would benefit greatly from the addition of this function. Dubuisson et al. [1] demonstrated that the Modified Hausdorff Distance (MHD) outperforms the directed Hausdorff Distance (HD).
I implemented unit tests and the benchmark for the new function in accordance with the contributing guidelines.

Best,
Robin

Reference
[1] M. P. Dubuisson and A. K. Jain. A Modified Hausdorff distance for object
matching. In ICPR94, pages A:566-568, Jerusalem, Israel, 1994.
http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=576361

Checklist

  • Docstrings for all functions
  • Gallery example in ./doc/examples (new features only)
  • Benchmark in ./benchmarks, if your changes aren't covered by an
    existing benchmark
  • Unit tests
  • Clean style in the spirit of PEP8
  • Descriptive commit messages (see below)

For reviewers

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.
  • Check that new features, API changes, and deprecations are mentioned in
    doc/release/release_dev.rst.

@pep8speaks
Copy link

pep8speaks commented Sep 26, 2021

Hello @robinthibaut! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 29:80: E501 line too long (83 > 79 characters)

Line 38:80: E501 line too long (83 > 79 characters)
Line 125:80: E501 line too long (83 > 79 characters)
Line 128:80: E501 line too long (83 > 79 characters)

Line 45:80: E501 line too long (80 > 79 characters)
Line 69:80: E501 line too long (80 > 79 characters)
Line 71:80: E501 line too long (80 > 79 characters)
Line 88:80: E501 line too long (80 > 79 characters)
Line 90:80: E501 line too long (80 > 79 characters)
Line 145:80: E501 line too long (87 > 79 characters)
Line 161:80: E501 line too long (80 > 79 characters)
Line 163:80: E501 line too long (80 > 79 characters)
Line 177:80: E501 line too long (80 > 79 characters)
Line 179:80: E501 line too long (83 > 79 characters)

Comment last updated at 2022-01-05 17:41:34 UTC

Copy link
Contributor

@grlee77 grlee77 left a comment

Choose a reason for hiding this comment

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

This looks like a good addition and should be simple to maintain. The method seems well known (the conference publication has >1800 citations on google scholar).

The code itself looks good, my only comment was whether we should incorporate it as an option in the existing function to reduce duplication.

skimage/metrics/set_metrics.py Outdated Show resolved Hide resolved
Comment on lines 179 to 180
np.mean(cKDTree(a_points).query(b_points, k=1)[0]),
np.mean(cKDTree(b_points).query(a_points, k=1)[0]),
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless I am mistaken, the only difference with the existing function is the change from np.max to np.mean here.

Given, that I am wondering if it would be better to just add an optional modified keyword-only argument to the existing function instead? (defaulting to False for backwards compatibility). What do others think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are correct, and I concur with your suggestion that adding a modified keyword to the original function would be more pythonic.
What course of action should we take? Should I combine the two functions as described above and commit the changes?

Copy link
Contributor

Choose a reason for hiding this comment

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

@robinthibaut, sorry I had missed this question. Yes, please just add the kwarg and code path to the original function and then remove this new function.

A "Notes" section in the docstring can be used to describe the difference for the "modified" case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@grlee77 I made the changes, and I hope it is now satisfactory.

@grlee77 grlee77 added the ⏩ type: Enhancement Improve existing features label Sep 29, 2021
Copy link
Contributor

@grlee77 grlee77 left a comment

Choose a reason for hiding this comment

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

Thanks @robinthibaut, this looks good to me now. I just made two small stylistic commits.

Copy link
Member

@rfezzani rfezzani left a comment

Choose a reason for hiding this comment

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

Thank you @robinthibaut, LGTM. I just left a style suggestion 😉

skimage/metrics/tests/test_set_metrics.py Outdated Show resolved Hide resolved
@robinthibaut
Copy link
Contributor Author

Thank you @robinthibaut, LGTM. I just left a style suggestion 😉

Thank you @rfezzani ! I made the changes according to your suggestion 🙂

Copy link
Member

@rfezzani rfezzani left a comment

Choose a reason for hiding this comment

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

🎉 Merging! Thank you @robinthibaut 👏

@rfezzani rfezzani merged commit a0fbb99 into scikit-image:main Jan 6, 2022
@lagru lagru mentioned this pull request Oct 4, 2022
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⏩ type: Enhancement Improve existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants