Ask Your Question
0

How to detect circular erosion/dilation

asked 2019-05-03 17:22:40 -0500

nikogamulin gravatar image

Hi,

I would like to detect circular erosions and dilations on a line. For dilations, I tried to recursively erode the image and on every recursion, I check width/height aspect ratio. If the ratio is smaller than 4, I assume that it the contour is circular and for each such contour I calculate circle center and radius from moments and area. This is the function that detects circular dilations:

def detect_circular_dilations(img, contours):
    contours_current, hierarchy = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    if len(contours_current) == 0:
        return get_circles_from_contours(contours)
    for c in contours_current:
        x, y, w, h = cv2.boundingRect(c)
        if w > h:
            aspect_ratio = float(w) / h
        else:
            aspect_ratio = float(h) / w
        if aspect_ratio < 4 and w < 20 and h < 20 and w > 5 and h > 5:
            contours.append(c)
    return detect_circular_dilations(cv2.erode(img, None, iterations=1), contours)

An example of circular dilation that I want to detect is the following:

image description

Another problem that I haven't solve is the detection of circular erosions. An example of circular erosion is the following:

image description

Here I've marked the circular erosion I would like to detect with red rectangle. There might be some smaller circular patterns (on the left) that shouldn't be treated as actual circular erosion.

Does anyone know what is the best way to detect such circular shapes? For circular dilations, I would appreciate any comment/suggestion in order to potentially make detection more robust.

Thank you!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-05-05 03:37:04 -0500

How about using below below method?

  1. Pushing the points of contours in white line edge.
  2. Using ransac to find two lines those are fit to upper and lower edge.
  3. Check the distance between the line point and the contour point.
  4. Detect the variance of those distance with 3 or 5 pixel widths.
  5. You could detect some threshold in both directional variance for erode and dilate cases.
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-05-03 17:22:40 -0500

Seen: 66 times

Last updated: May 03