Repository navigation
Ensure watershed auto-markers respect mask - #3809
Conversation
|
Hello @jni! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2019-03-26 12:26:38 UTC |
lagru
left a comment
There was a problem hiding this comment.
Only some small comments / questions. Using local minima as seed points in case of None is nice new feature!
| "`image` (shape {})".format(mask.shape, image.shape)) | ||
| raise ValueError(message) | ||
| if markers is None: | ||
| from .extrema import local_minima |
There was a problem hiding this comment.
What's the reasoning for making this a lazy import?
There was a problem hiding this comment.
extrema imports from watershed (the offsets to raveled neighbors), so not using this resulted in a circular import. I guess the correct way is to move offsets to its own utility file.
| from .extrema import local_minima | ||
| markers_bool = local_minima(image, connectivity=connectivity) * mask | ||
| markers = ndi.label(markers_bool)[0] | ||
| elif not isinstance(markers, (np.ndarray, list, tuple)): |
There was a problem hiding this comment.
Not sure if I missed something but wouldn't it be more readable to remove the not and switch the bodies of this elif- and the following else-statements? Maybe even test for "int-ness" and add a third branch that raises a nice TypeError if markers has an unsupported type?
There was a problem hiding this comment.
Possibly this is true, I'm not sure about the original rationale, this is not new code. I'll change it.
| The desired number of markers, or an array marking the basins with the | ||
| values to be assigned in the label matrix. Zero means not a marker. | ||
| values to be assigned in the label matrix. Zero means not a marker. If | ||
| no markers are given, the local minima of the image are used as |
There was a problem hiding this comment.
Nitpick: I think "no markers" may be confused with giving 0 or passing in an array that is False everywhere.
| no markers are given, the local minima of the image are used as | |
| no ``None``, the local minima of the image are used as |
Maybe remove "Zero means not a marker." and just display a warning if the input leads to no seeds being defined. Is there a use case where this doesn't hint at a usage error?
There was a problem hiding this comment.
If None (no markers provided), the local minimal of the image...
| data = blob | ||
| mask = (data != 255) | ||
| out = watershed(data, 25, connectivity=2, mask=mask) | ||
| # There should be no markers where the mask is false |
There was a problem hiding this comment.
Why do you call this markers? For me markers and seeds are synonyms, corresponding to marked pixels from which the watershed flooding is done. How about "labeled pixels"? Sorry to be nitpicking about a comment in a test ;-).
There was a problem hiding this comment.
OK, I think I got it, we're talking about the same thing for markers, you just want to check that no marker was chosen outside the mask, so that all pixels outside the mask in the segmentation are set to zero. OK!
|
The code looks fine to me. Just a question, why did you use |
|
@emmanuelle we've had a lot of issues with So I much prefer using |
|
@lagru @emmanuelle I believe I have addressed your concerns. =) |
|
Hmm, failure in Py3.7 that seems unrelated to this PR:
I'll see if I can fix it. |
|
Merging, thanks! |
Description
Fixes #3808
Additionally, I took the opportunity to allow watershed without passing in markers. Then the local minima in the image are used.
Checklist
Gallery example in./doc/examples(new features only)./benchmarks, if your changes aren't covered by anexisting benchmark
For reviewers
later.
__init__.py.doc/release/release_dev.rst.@meeseeksdev backport to v0.14.x