The Wayback Machine - https://web.archive.org/web/20201010190000/https://github.com/scikit-image/scikit-image/pull/4760
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

Refactor and fix peak_local_max #4760

Open
wants to merge 26 commits into
base: master
from

Conversation

@rfezzani
Copy link
Member

@rfezzani rfezzani commented May 27, 2020

Description

In my attempt to fix #2592, I made a review of the code and found many issues (see #4756, #4749, #4752 and #3990 (comment)). It appeared to me that a global refactoring of peak_local_max is necessary.

Multiple changes are applied in this PR:

  • min_distance is enforced in the same way as in #4218 for corner_peak (see here)
  • edge cases as described in #4749 are managed here
  • trivial image case issue #3990 is managed here
  • private functions _get_threshold and _get_excluded_border_width are introduced for readability
  • labels managing is optimized, in particular:
  • return strategy is simplified.

If accepted, this PR allows to deprecate corner_peak that becomes a duplicate of peak_local_max.

Fixes #2592. Fixes #4756. Fixes #4756. Closes #3990.

Checklist

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.
rfezzani added 2 commits May 28, 2020
skimage/feature/peak.py Outdated Show resolved Hide resolved
rfezzani and others added 2 commits Jul 27, 2020
Co-authored-by: Marianne Corvellec <[email protected]>
@rfezzani
Copy link
Member Author

@rfezzani rfezzani commented Jul 27, 2020

Thank you @mkcor for your review ;)

@rfezzani rfezzani changed the title Refactor and fix peack_local_max Refactor and fix peak_local_max Aug 27, 2020
@sciunto sciunto self-requested a review Aug 29, 2020
@sciunto sciunto self-assigned this Aug 29, 2020
…into Fix_peack_local_max
@rfezzani
Copy link
Member Author

@rfezzani rfezzani commented Sep 14, 2020

Can we plan this PR for 0.18 or is the schedule too short?

tree = spatial.cKDTree(coord)

indices = tree.query_ball_point(coord, r=min_distance, p=p_norm)
rejected_peaks_indices = set()
for idx, candidates in enumerate(indices):
if idx not in rejected_peaks_indices:
candidates.remove(idx)
rejected_peaks_indices.update(candidates)

# Remove the peaks that are too close to each other
coord = np.delete(coord, tuple(rejected_peaks_indices), axis=0)
Comment on lines 21 to 31

This comment has been minimized.

@lagru

lagru Sep 29, 2020
Member

Several suggestions here:

  • We can skip this step if min_distance is 1, correct?
  • Also, it's probably best to update the description of that parameter in the docstring similar to #4218? I think the part with "2 * min_distance + 1" could be clearer.
  • As already suggested in #4218 it's probably best to factor this out? Maybe even to Cython to get rid of the slow loop (doesn't have to be this PR)?

This comment has been minimized.

@rfezzani

rfezzani Oct 2, 2020
Author Member

Thank you @lagru for your review, and sorry for my late answer, I have been too much busy these last few days 🙏.

  • We can skip this step if min_distance is 1, correct?

No, we also want to remove the adjacent peaks (I may be didn't get your point here 😕).

  • Also, it's probably best to update the description of that parameter in the docstring similar to #4218? I think the part with "2 * min_distance + 1" could be clearer.

👍

  • As already suggested in #4218 it's probably best to factor this out? Maybe even to Cython to get rid of the slow loop (doesn't have to be this PR)?

Why not, I remember that we already mentioned this ;)

This comment has been minimized.

@rfezzani

rfezzani Oct 7, 2020
Author Member

@lagru, I factored out this part as you suggested in the skimage._shared.coord.ensure_spacing function, I hope you agree with the function name and its API.

This comment has been minimized.

@lagru

lagru Oct 8, 2020
Member

Thank you. The name seems fine to me. Did you intentionally not replace the appropriate code snippet in corner_peaks with ensure_spacing?

This comment has been minimized.

@rfezzani

rfezzani Oct 8, 2020
Author Member

With this Fix of peak_local_max, corner_peaks becomes obsolete and can directly be replaced by the former.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.