给定一个固定大小的二进制正方形数组,如下图所示。 预先假定该数组包含一个圆或其一部分的图像。这个圈子总是以图像为中心是很重要的。如何将圆弧延伸至完整的圆形?
有必要找到弧补充到整圆的有效方法,如果可能的话。
我试图统计计算从中心到白点的平均距离并完成圆圈。它的工作原理。我也尝试了霍夫变换来拟合椭圆并确定其大小。但是这两种方法都非常耗费资源。
1方法的草图:
points = np.transpose(np.array(np.nonzero(array))).tolist() # array of one-value points
random.shuffle(points)
points = np.array(points[:500]).astype('uint8') # take into account only 500 random points
distances = np.zeros(points.shape[0], dtype='int32') # array of distances from the centre of image (40, 40) to some point
for i in xrange(points.shape[0]):
distances[i] = int(np.sqrt((points[i][0] - 40) ** 2 + (points[i][1] - 40) ** 2))
u, indices = np.unique(distances, return_inverse=True)
mean_dist = u[np.argmax(np.bincount(indices))] # most probable distance
# use this mean_dist in order to draw a complete circle
2方法的草图:
from skimage.transform import hough_ellipse
result = hough_ellipse(array, min_size=..., max_size=...)
result.sort(order='accumulator')
# ... extract the necessary info from result variable if it's not empty
可能有人建议另一个和有效的解决方案?谢谢!
显示您的尝试! – Astrom
这是一个有效且很好的问题,但没有代码,它看起来非常宽泛,并且没有针对任何给定的标签。它可能更适合其他SE站点,如DSP。 – iled