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

Make join_segmentations return array maps from output to input labels #6786

Merged
merged 5 commits into from
Mar 11, 2023

Conversation

aeisenbarth
Copy link
Contributor

Description

This is an implementation for #6785.

It adds as optional return value two ArrayMaps which allow tracing the labels of the returned segmentation back to the labels of the two input segmentations.

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.
  • There is a bot to help automate backporting a PR to an older branch. For
    example, to backport to v0.19.x after merging, add the following in a PR
    comment: @meeseeksdev backport to v0.19.x
  • To run benchmarks on a PR, add the run-benchmark label. To rerun, the label
    can be removed and then added again. The benchmark output can be checked in
    the "Actions" tab.

@aeisenbarth aeisenbarth force-pushed the join-segmentations-mappings branch from d6b8b01 to fb09efe Compare March 7, 2023 21:34
@aeisenbarth
Copy link
Contributor Author

  • In my original code, I used more expressive names also for s1, j etc. I can changed variable names if desired.
  • I would also add type hints (although the existing code didn't have).

Copy link
Member

@jni jni left a comment

Choose a reason for hiding this comment

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

@aeisenbarth very cool!

In the long term for scikit-image, we are moving away from return_something= arguments that change the return type, because they make typing very awkward. However, since we haven't quite decided yet what we'll replace it with 😅, I'm personally in favour of merging this. It's a very nice addition. I have left a couple of suggestions, but otherwise I'll approve once fixed. Thanks!!!

skimage/segmentation/_join.py Outdated Show resolved Hide resolved
skimage/segmentation/_join.py Outdated Show resolved Hide resolved
skimage/segmentation/_join.py Outdated Show resolved Hide resolved
@aeisenbarth
Copy link
Contributor Author

Shall I also add type hints? (I don't know whether scikit-image has any constraints on compatibility with older Python syntax).
Does scikit-image have any preferred array type hints?

Something like this should correctly describe the optional return values:

@overload
def join_segmentations(
    s1: np.ndarray, s2: np.ndarray, return_mapping: Literal[False] = False
) -> np.ndarray:
    ...


@overload
def join_segmentations(
    s1: np.ndarray, s2: np.ndarray, return_mapping: Literal[True]
) -> Tuple[np.ndarray, ArrayMap, ArrayMap]:
    ...


def join_segmentations(
    s1: np.ndarray, s2: np.ndarray, return_mapping: bool = False
) -> Union[np.ndarray, Tuple[np.ndarray, ArrayMap, ArrayMap]]:

@lagru
Copy link
Member

lagru commented Mar 9, 2023

Although, long-term type hints are the direction we want to go, right now they wouldn't be consistent with the rest of the library. So I'd say we don't need to add them in this PR.

Thanks for introducing me to the overload decorator! 😊 That could be quite useful down the line.

@jni
Copy link
Member

jni commented Mar 10, 2023

Shall we merge this then? =)

@lagru
Copy link
Member

lagru commented Mar 10, 2023

Shall we merge this then? =)

Happy to. Just didn't get around to review this yet...

@jni jni merged commit a617c39 into scikit-image:main Mar 11, 2023
@jni
Copy link
Member

jni commented Mar 11, 2023

@lagru you're a busy man right now so I decided to save you some trouble 😂

decorouz pushed a commit to decorouz/scikit-image that referenced this pull request Mar 13, 2023
…scikit-image#6786)

Fixes scikit-image#6785.

Adds as optional return value two ArrayMaps that allow tracing the labels of the returned segmentation back to the labels of the two input segmentations.

* Make join_segmentations return array maps from output to input labels
* Remove obsolete assertion
* Rename variables
* Reorder optional operation
* Make example more comprehensible
decorouz pushed a commit to decorouz/scikit-image that referenced this pull request Mar 15, 2023
…scikit-image#6786)

Fixes scikit-image#6785.

Adds as optional return value two ArrayMaps that allow tracing the labels of the returned segmentation back to the labels of the two input segmentations.

* Make join_segmentations return array maps from output to input labels
* Remove obsolete assertion
* Rename variables
* Reorder optional operation
* Make example more comprehensible
@jarrodmillman jarrodmillman added this to the 0.21 milestone Apr 5, 2023
@lagru lagru added ⏩ type: Enhancement Improve existing features 📜 type: API Involves API change(s) labels May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⏩ type: Enhancement Improve existing features 📜 type: API Involves API change(s)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants