-
-
Couldn't load subscription status.
- Fork 51
Add label merging function (and improve ndmeasure.label) #409
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
Open
m-albert
wants to merge
6
commits into
dask:main
Choose a base branch
from
m-albert:improve_labels_and_add_merge_functionality
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add label merging function (and improve ndmeasure.label) #409
m-albert
wants to merge
6
commits into
dask:main
from
m-albert:improve_labels_and_add_merge_functionality
+568
−108
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…w/high bit encoding rather than additive scheme
…includes new functionality) and relabel_sequential. merge_labels_across_chunk_boundaries. Refactor ndmeasure.label to use the new functions. Rewrite relabel_blocks to handle sparse and large values relabeling efficiently. Add tests for new functionality.
|
Hey @m-albert I am currently very overwhelmed with stuff but I wanted to say this is awesome 🤩 and something I have wanted for about 15 years! |
|
Thanks @jni 🤗 Glad you like it and that you had the same idea! Regarding this PR I still need to get an (obscurely) failing test under control... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

PR
This PR contains work I've been wanting to discuss and push here for a while.
Highlights:
ndmeasure.label:ndmeasure.labeldoesn't output contiguous (sequential) labels (also before implementing the point above). This PR adds a parameterproduce_sequential_labelstodask_image.ndmeasure.labelto output contiguous labels.skimage.segmentation.relabel_sequential:ndmeasure.relabel_sequential(this provides the functionality e.g. of the point above, happy to discuss whether the function should be public)ndmeasure.merge_labels_across_chunk_boundaries(details below)merge_labels_across_chunk_boundaries
What's the idea behind
ndmeasure.merge_labels_across_chunk_boundaries?Visual abstract
Cases of overlap = 0 (top) and overlap > 0 (bottom)
Description
From the docstring:
Example
Consider the following problem.
The user wants to segment a large input image, i.e. a dask array.
and has a segmentation method that cannot be applied on the entire image (e.g. memory or method constraints) but works well on regions of the input image. The user can use
map_overlapto apply the segmentation on the chunks of the input image and include overlap so that the segmentation method performs well on the chunk boundaries:At this point, the user faces two challenges:
This is where
ndmeasure.merge_labels_across_chunk_boundariescomes in to merge labels across chunk boundaries.First use case / usage pattern
Similarly to the implementation of
ndmeasure.labeland e.g. the approach provided in distributed cellpose (ping @GFleishman), one approach for merging labels consists in merging labels that touch across chunk boundaries.ndmeasure.merge_labels_across_chunk_boundariesallows to do this in a way that's agnostic of the segmentation method:Second use case
The approach above joins all labels that form part of the same connected component in a boundary slice of thickness one. This can lead to artefacts. In fact, the example image above contains two merged cells which are clearly separated in the chunkwise segmentation. To separate these,
dask_image.ndmeasure.merge_labels_across_chunk_boundarieshas the option to merge labels based on the IoU within an overlap region.The labels of the two cells below which previously had been joined now remain separated.
Finally
In my personal projects it's been useful to have a function that merges labels across chunks. I think
dask-imagecould be a good place for providing such functionality to the community and I've had some offline feedback at meetings that this could be useful. Happy about any further feedback / discussion over here!