Repository navigation
Refactor canny edge detector - #4342
Conversation
| raise ValueError("Quantile thresholds must not be < 0.0") | ||
|
|
||
| def fsmooth(x): | ||
| return img_as_float(gaussian(x, sigma, mode='constant')) |
There was a problem hiding this comment.
In the previous version, preserve_range was implicitly set to False as the default argument of gaussian
| pts_plus = (isobel >= 0) & (jsobel >= 0) & (abs_isobel >= abs_jsobel) | ||
| pts_minus = (isobel <= 0) & (jsobel <= 0) & (abs_isobel >= abs_jsobel) | ||
| pts = pts_plus | pts_minus |
There was a problem hiding this comment.
These boolean expressions are simplified in _get_local_maxima
| c1 = magnitude[1:, :][pts[:-1, :]] | ||
| c2 = magnitude[1:, 1:][pts[:-1, :-1]] | ||
| m = magnitude[pts] | ||
| w = abs_jsobel[pts] / abs_isobel[pts] | ||
| c_plus = c2 * w + c1 * (1 - w) <= m | ||
| c1 = magnitude[:-1, :][pts[1:, :]] | ||
| c2 = magnitude[:-1, :-1][pts[1:, 1:]] | ||
| c_minus = c2 * w + c1 * (1 - w) <= m | ||
| local_maxima[pts] = c_plus & c_minus |
There was a problem hiding this comment.
This interpolation step is performed in _set_local_maxima
use_quantile argument usage in canny edge detector
use_quantile argument usage in canny edge detectortile up to size 2048, 2048 to get closer to 1 s runtime for canny
|
Excellent! No worry @grlee77, thank you 😉 |
When mask=None, we can avoid binary morphology and just set the edge values to zero instead. We also do not need to Gaussian filter the mask
We really only need to know if sum > 0, not the actual value, so can use numpy.unique on the masked values instead.
359a8a8 to
2aea7db
Compare
|
I ran the benchmark on bbc4460, which is just this PR immediately after addition of the benchmark itself. The last two performance-related commits were ported from #5162. Unlike in the other PR, I ran these benchmarks with
Rather than hard-coding |
grlee77
left a comment
There was a problem hiding this comment.
The style changes here look good to me.
@rfezzani, please review the three commits I had added. For the benchmark, I think there was an error in setting up the test image previously because it contained only noise! I switched to using the astronaut image as a more realistic case.
I can confirm that the changes here give the same result as for the image comparison in the first commit of #5162. It may be worth changing the default mode='constant' to mode='nearest' or mode='reflect' to keep results the most similar to before in the unmasked case.
|
@sciunto, do you still see requested changes? Thank you for your time ;) |
move comments within _get_local_maxima to its docstring remove comments from canny that duplicate the text of the docstring
|
@sciunto: I think this is ready, but it needs you to mark the requested changes as resolved to proceed. One outstanding issue to be left to a separate PR is changing the default mode to 'nearest'. |
|
Thanks @rfezzani! |
Description
In this PR, the
skimage.feature._cannymodule is refactored:low_thresholdandhigh_thresholddefault values are now respectively0.1and0.2instead ofNone.settinglow_thresholdandhigh_thresholdtoNoneis deprecatedthepreserve_rangeargument is added to manage the issue use_quantiles description in canny is incorrect #4282:low_thresholdandhigh_thresholdare only divided bydtype_maxifpreserve_rangeis False.ValueErroris raised iflow_threshold > high_thresholdsmooth_with_function_and_maskis deprecated_preprocess,_get_local_maximaand_set_local_maximaare defined.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.@meeseeksdev backport to v0.14.x