这篇论文似乎与我的问题非常相关,但我无法在网上找到代码。
还有基于凹点和椭圆拟合的接触细胞分割也是一个有用的参考。
我也在尝试理解他们的算法。我卡在了如何找到接触对象的凹点。
这是我的代码:
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()
目的:
我想获取下方的凹点并适配椭圆。我的代码只是包裹极端点。
任何帮助或指导都将不胜感激。提前致谢。