给定一个固定大小的二进制正方形数组,如下图所示。 预先假定数组包含一个圆或其一部分的图像。这个圆总是以图像为中心是很重要的。你知道吗
如果可能的话,有必要找到一种有效的方法将圆弧补充到整圆上。你知道吗
我试着从统计学上计算出从中心到白点的平均距离,然后完成这个圆。而且很有效。我还尝试了Hough变换来拟合椭圆并确定它的大小。但这两种方法都是资源密集型的。你知道吗
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
有人能提出另一个有效的解决办法吗?谢谢您!你知道吗
这似乎是个好的开始。给定一个
n
像素的图像,这个算法就是O(n)
,已经非常有效了。你知道吗如果想要更快的实现,请尝试使用随机化:
从图像中随机抽取
m
个样本点,并用这些样本点计算白点的平均半径。然后用这个半径完成这个圆。你知道吗这个算法将有
O(m)
,这意味着它对所有m < n
都更快。为m
选择一个好的值可能很棘手,因为您必须在运行时和输出质量之间进行折衷。你知道吗相关问题 更多 >
编程相关推荐