fitting a circle to a binary image

前端 未结 5 966
Happy的楠姐
Happy的楠姐 2020-12-15 12:48

I have been using skim age\'s thresholding algorithms to get some binary mask. For example, I obtain binary images like this:

5条回答
  •  一个人的身影
    2020-12-15 13:39

    This should in general give very good and robust results:

    import numpy as np
    from skimage import measure, feature, io, color, draw
    
    img = color.rgb2gray(io.imread("circle.jpg"))
    img = feature.canny(img).astype(np.uint8)
    img[img > 0] = 255
    
    coords = np.column_stack(np.nonzero(img))
    
    model, inliers = measure.ransac(coords, measure.CircleModel,
                                    min_samples=3, residual_threshold=1,
                                    max_trials=500)
    
    print model.params
    
    rr, cc = draw.circle(model.params[0], model.params[1], model.params[2],
                         shape=img.shape)
    
    img[rr, cc] = 128
    

提交回复
热议问题