You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
hough_circle_peaks not respecting min_xdistance, min_ydistance. #2728
It is clear from the image above that, for instance, the first coin (and second) has two circles whose centers are much closer that 50 pixels in any of the dimensions.
Linux Debian
Python 3.5.2
scikit image Version: 0.13.0
So we can see that this is because each radius is being processed independently of the rest (including wrt min_xdistance, min_ydistance), so I guess the needs decision that @soupault flagged here was whether that should be the case or not.
The fix would require doing 3d peak finding where normalize would need to be set to true to not bias toward larger radii.
I'm happy to implement this fix if we get a consensus on this.
UPDATE: I've implemented a specialised 3d peak finding that uses a max-projection along the "radii axis" from the hough transform (i.e. it doesn't need to use a maximum_filter1d along that axis).
So we can see that this is because each radius is being processed independently of the rest (including wrt min_xdistance, min_ydistance), so I guess the needs decision that @soupault flagged here was whether that should be the case or not.
I'm not an active user of this function, but I'd expect it to consider all Hough spaces jointly. This just seems more natural. Also, if implemented this way, the current behaviour could be largely reproduced by iterating over hspaces in user code. @jmetz I'd vote to make the proposed changes.
NB: The new _prominent_peaks3d I created isn't simply a generalization of _prominent_peaks, as the z-direction is "special" in that the maximum is across that whole dimension, not just within some minimum distance.
For this reason it's use is quite specific... which is why I'm hesitant to submit PR in current form.
What's the status on this problem? I'm using scikit 0.15, and it's still turning up.
Since it seems a fix has already been implemented. I'm not sure what the problem is. From my experience using the Hough-Transform for circle detection, the current behaviour just isn't useful. You have to manually code what the function already claims to do.
If nothing else, correcting the documentation to accurately reflect what min_xdistance (and y version) does would be nice. Right now it says "Minimum distance separating centers in the x dimension", which it definitely does not.
Here's code producing the issue, based on the example. It gets even clearer if you only use the small part [160:230, 70:270]:
import numpy as np
import matplotlib.pyplot as plt
from skimage import data, color
from skimage.transform import hough_circle, hough_circle_peaks
from skimage.feature import canny
from skimage.draw import circle_perimeter
from skimage.util import img_as_ubyte
# Load picture and detect edges
image = img_as_ubyte(data.coins())#[160:230, 70:270]
edges = canny(image, sigma=3, low_threshold=10, high_threshold=50)
# Detect two radii
hough_radii = np.arange(15, 35, 2)
hough_res = hough_circle(edges, hough_radii)
# Select the most prominent 5 circles
accums, cx, cy, radii = hough_circle_peaks(hough_res, hough_radii, total_num_peaks=24,
min_xdistance=50, min_ydistance=50)
# Draw them
fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(10, 4))
image = color.gray2rgb(image)
for center_y, center_x, radius in zip(cy, cx, radii):
circy, circx = circle_perimeter(center_y, center_x, radius)
image[circy, circx] = (255, 0, 0)
ax.imshow(image, cmap=plt.cm.gray)
plt.show()
@jmetz even without a PR, I just saw that your comment above does not include a link to your solution! “I have discovered a remarkable solution to this issue which this comment is too small to contain.” =P
Would you mind sharing your code e.g. as a gist? A PR with a private function would also be appreciated.
@jmetz even without a PR, I just saw that your comment above does not include a link to your solution! “I have discovered a remarkable solution to this issue which this comment is too small to contain.” =P
Would you mind sharing your code e.g. as a gist? A PR with a private function would also be appreciated.
You're right @jni - I'd intended to find time to create a proper solution and PR, but that time never materialised (does it ever!?).
Activity
jmetz commentedon May 9, 2018
So we can see that this is because each radius is being processed independently of the rest (including wrt
min_xdistance,min_ydistance), so I guess theneeds decisionthat @soupault flagged here was whether that should be the case or not.The fix would require doing 3d peak finding where
normalizewould need to be set to true to not bias toward larger radii.I'm happy to implement this fix if we get a consensus on this.
jmetz commentedon May 9, 2018
UPDATE: I've implemented a specialised 3d peak finding that uses a max-projection along the "radii axis" from the hough transform (i.e. it doesn't need to use a
maximum_filter1dalong that axis).It seems to work and fixes the issue above.
Happy to put in a PR once we get consensus :)
soupault commentedon May 11, 2018
I'm not an active user of this function, but I'd expect it to consider all Hough spaces jointly. This just seems more natural. Also, if implemented this way, the current behaviour could be largely reproduced by iterating over hspaces in user code. @jmetz I'd vote to make the proposed changes.
On top of this, FWIW, the documentation for
total_num_peaksparameter is way to vague (http://scikit-image.org/docs/dev/api/skimage.transform.html#skimage.transform.hough_circle_peaks).jni commentedon Jul 10, 2018
@jmetz wanna make that PR? ;) See https://stackoverflow.com/questions/51242987/python-skimage-transform-hough-circle-peaks-min-xdistance-and-min-ydistance-e
=)
jmetz commentedon Jul 10, 2018
@jni - thanks for the nudge, I had this sitting around and forgotten about it =D
Ok so details on the way I fixed this:
I created a new 3D version of the
_prominent_peaks(https://github.com/scikit-image/scikit-image/blob/master/skimage/feature/peak.py#L198), and then simply call this on thehspacesinhough_circle_peaks, instead of iterating over each radius as was previous done (https://github.com/scikit-image/scikit-image/blob/master/skimage/transform/hough_transform.py#L269).Does that sound reasonable? If so I'll submit the PR.
jmetz commentedon Jul 10, 2018
NB: The new
_prominent_peaks3dI created isn't simply a generalization of_prominent_peaks, as the z-direction is "special" in that the maximum is across that whole dimension, not just within some minimum distance.For this reason it's use is quite specific... which is why I'm hesitant to submit PR in current form.
BurnNote commentedon Apr 19, 2019
What's the status on this problem? I'm using scikit 0.15, and it's still turning up.
Since it seems a fix has already been implemented. I'm not sure what the problem is. From my experience using the Hough-Transform for circle detection, the current behaviour just isn't useful. You have to manually code what the function already claims to do.
If nothing else, correcting the documentation to accurately reflect what min_xdistance (and y version) does would be nice. Right now it says "Minimum distance separating centers in the x dimension", which it definitely does not.
Here's code producing the issue, based on the example. It gets even clearer if you only use the small part [160:230, 70:270]:
VolkerH commentedon Jul 19, 2019
Just ran into this as well, despite setting minimum distances of 300 pixels many circle centres are just a few pixels apart.
Currently using
cv2.HoughCirclesas a workaround.@jni should be able to guess what I need this for.
jni commentedon Jul 24, 2019
@jmetz even without a PR, I just saw that your comment above does not include a link to your solution! “I have discovered a remarkable solution to this issue which this comment is too small to contain.” =P
Would you mind sharing your code e.g. as a gist? A PR with a private function would also be appreciated.
jmetz commentedon Jul 24, 2019
You're right @jni - I'd intended to find time to create a proper solution and PR, but that time never materialised (does it ever!?).
I've created a gist for this here.
rfezzani commentedon Feb 7, 2020
Fixed in #4350. Thank you @xiaoyu-wu and thank you @tonypower for reporting.