Is there a way to "extract" and detect concave point to fit ellipses?

Viewed 370

This paper seems very relevant to my problem but I can find the code online.

Splitting touching cells based on concave points and ellipse fitting as well.

I'm also trying to understand their algorithm. I'm stuck at finding the concave points of touching objects.

Here is my code:

import numpy as np
import cv2

img = cv2.imread("binary_img.png")
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

ret,thresh_img = cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV)
thresh_img = 255- thresh_img
contours, hierarchy = cv2.findContours(thresh_img,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

hull = []

# calculate points for each contour
for i in range(len(contours)):
    # creating convex hull object for each contour
    hull.append(cv2.convexHull(contours[i], False))

# create an empty black image
drawing = np.zeros((thresh_img.shape[0], thresh_img.shape[1], 3), np.uint8)

# draw contours and hull points
for i in range(len(contours)):
    color_contours = (0, 255, 0) # green - color for contours
    color = (255, 0, 0) # blue - color for convex hull
    # draw ith contour
    cv2.drawContours(drawing, contours, i, color_contours, 1, 8, hierarchy)
    # draw ith convex hull object
    cv2.drawContours(drawing, hull, i, color, 1, 8)

cv2.imwrite("19_drawing.png", drawing)
cv2.imshow("Drawing", drawing)
cv2.waitKey()

binary image

Contours

AIM:

I would like to get the concave points below and fit an ellipse. My code is simply wrapping the extremities.

Any help or direction would be appreciated. Thanks in advance.

Goal

0 Answers
Related