-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add default level parameter in measure.find_contours #4862
Conversation
Hello @rubywerman! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-08-06 05:42:59 UTC |
skimage/measure/_find_contours.py
Outdated
@@ -9,7 +9,7 @@ | |||
|
|||
|
|||
@deprecate_kwarg({'array': 'image'}, removed_version="0.20") | |||
def find_contours(image, level, | |||
def find_contours(image, level='median', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting the default to a string may suggest that other string values are accepted ('mean' for example)
def find_contours(image, level='median', | |
def find_contours(image, level=None, |
Thank you for your feedback @rfezzani! I updated the parameter as you suggested :) |
Thanks for the PR @rubywerman! The discussion about which default level to choose was not completely settled in #4813, there is also the possibility in taking (max - min)/2. The latter choice is mostly useful for binary arrays while the median makes more sense for float arrays. I'd argue that binary arrays are the typical case where one does not want to specify the value of the level, because there is really only one value which makes sense. So I have a slight preference for (max - min)/2 but the median also makes sense. Please also add a test which executes |
Thanks for the feedback @emmanuelle! I will add the test. Also, could it be beneficial to have two default values, |
I agree with @sciunto that having different behaviour based on the input type isn't ideal. I have commented on the original issue, but my suggestion would be to have |
I have reconsidered my initial doubts. Given the fact that there is the possibility to pass a value, and that for a binary image other contours than 0.5 (in fact anything strictly between 0 and 1) will also good give results, we have to accept that there are several possible good solutions and just choose one of them. The one you suggest @jni is a good one, in fact the original median value proposed by @rubywerman is also good (and simple to explain). |
skimage/measure/_find_contours.py
Outdated
@@ -24,7 +24,8 @@ def find_contours(image, level, | |||
image : 2D ndarray of double | |||
Input image in which to find contours. | |||
level : float | |||
Value along which to find contours in the array. | |||
Value along which to find contours in the array. By default, the level | |||
is set to the median value of the array. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also change the docstring :-)
@@ -130,3 +130,40 @@ def test_invalid_input(): | |||
find_contours(r, 0.5, 'foo', 'bar') | |||
with testing.raises(ValueError): | |||
find_contours(r[..., None], 0.5) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for adding all these tests :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @rubywerman ! I think the PR is ready now.
skimage/morphology/convex_hull.py
Outdated
if image.ndim > 2: | ||
raise ValueError("Input must be a 2D image") | ||
if image.ndim > 3: | ||
raise ValueError("Input must be a 2D or 3D image") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my mistake– it shouldn't. fixing now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought @rubywerman was fixing #4865 at the same time :-) (but it can be in another PR, with a test ;-))
I approve it as well, I'm just waiting for the CI. Thank you for your contribution. |
Merging, thank you @rubywerman ! |
Description
Fixes #4813
This PR adds the median as the default level parameter in
find_contours
. After reading the discussion in #4813 and looking at different image arrays [see notebook], I thought the median could be a good default value.Checklist
./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
.