Skip to content

hough_circle_peaks not respecting min_xdistance, min_ydistance. #2728

Closed

Description

@tonypower

Description

It looks like hough_circle_peaks is not respecting min_xdistance, min_ydistance. Below I provide an example that is just a modified version of the example provided in http://scikit-image.org/docs/dev/auto_examples/edges/plot_circular_elliptical_hough_transform.html

Way to reproduce

hough_radii = np.arange(15, 35, 2)
hough_transf = hough_circle(edges, hough_radii)
accums, cx, cy, radii = hough_circle_peaks(hough_transf, hough_radii, total_num_peaks=24,
                                               min_xdistance=50, min_ydistance=50)

image = color.gray2rgb(image)
    
for center_y, center_x, radius in zip(cy, cx, radii):
     circy, circx = draw.circle_perimeter(center_y, center_x, radius)
     image[circy, circx] = (255, 0, 0)

hough_circle_skimage

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

Thanks,

Activity

  1. added this to the 0.14.1 milestone on Jan 16, 2018
  2. modified the milestones: 0.14.1, 0.14 on Apr 27, 2018
  3. jmetz commented on May 9, 2018

    @jmetz
    Contributor

    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.

  4. jmetz commented on May 9, 2018

    @jmetz
    Contributor

    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).

    It seems to work and fixes the issue above.

    Happy to put in a PR once we get consensus :)

  5. soupault commented on May 11, 2018

    @soupault
    Member

    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.

    On top of this, FWIW, the documentation for total_num_peaks parameter is way to vague (http://scikit-image.org/docs/dev/api/skimage.transform.html#skimage.transform.hough_circle_peaks).

  6. modified the milestones: 0.14, 0.15 on May 23, 2018
  7. jmetz commented on Jul 10, 2018

    @jmetz
    Contributor

    @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 the hspaces in hough_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.

  8. jmetz commented on Jul 10, 2018

    @jmetz
    Contributor

    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.

  9. BurnNote commented on Apr 19, 2019

    @BurnNote

    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()
    
    
  10. modified the milestones: 0.15, 0.16 on Apr 20, 2019
  11. VolkerH commented on Jul 19, 2019

    @VolkerH
    Contributor

    Just ran into this as well, despite setting minimum distances of 300 pixels many circle centres are just a few pixels apart.

    image

    Currently using cv2.HoughCircles as a workaround.
    @jni should be able to guess what I need this for.

  12. jni commented on Jul 24, 2019

    @jni
    Member

    @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.

  13. jmetz commented on Jul 24, 2019

    @jmetz
    Contributor

    @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!?).

    I've created a gist for this here.

  14. rfezzani commented on Feb 7, 2020

    @rfezzani
    Member

    Fixed in #4350. Thank you @xiaoyu-wu and thank you @tonypower for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions