給定一個固定大小的二進制正方形數組,如下圖所示。 預先假定該數組包含一個圓或其一部分的圖像。這個圈子總是以圖像爲中心是很重要的。如何將圓弧延伸至完整的圓形?
有必要找到弧補充到整圓的有效方法,如果可能的話。
我試圖統計計算從中心到白點的平均距離並完成圓圈。它的工作原理。我也嘗試了霍夫變換來擬合橢圓並確定其大小。但是這兩種方法都非常耗費資源。
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