首页 文章

拟合曲线到分段图像

提问于
浏览
6

在我目前的数据分析中,我有一些分段图像,例如下面 .

我的问题是我想在分割图像中将多项式或样条(s.th.of维)拟合到某个区域(红色) . (结果将是黑线) .

通常我会使用像正交距离回归这样的东西,问题是这需要某种拟合函数,在这种情况下我没有 . 那么使用python / numpy执行此操作的最佳方法是什么?对于这类问题,是否有一些标准算法?

example

更新:看起来我的绘图技巧可能不是最好的,图片中的红色区域也可能有一些随机噪音而且不必完全连接(由于噪音可能会有小间隙) .

更新2:总体目标是具有参数化曲线p(t),其返回[0,1]中t的位置,即p(t)=>(x,y) . 其中t = 0开始黑线,t = 1黑线结束 .

1 回答

  • 3

    我使用scipy.ndimagethis gist作为模板 . 这让你几乎到了那里,你将不得不找到一种合理的方法来从大多数骨架化的图像中参数化曲线 .

    from scipy.misc import imread
    import scipy.ndimage as ndimage
    
    # Load the image
    raw = imread("bG2W9mM.png")
    
    # Convert the image to greyscale, using the red channel
    grey = raw[:,:,0]
    
    # Simple thresholding of the image
    threshold = grey>200
    
    radius = 10
    distance_img = ndimage.distance_transform_edt(threshold)
    morph_laplace_img = ndimage.morphological_laplace(distance_img, 
                                                      (radius, radius))
    skeleton = morph_laplace_img < morph_laplace_img.min()/2
    
    import matplotlib.cm as cm
    from pylab import *
    subplot(221); imshow(raw)
    subplot(222); imshow(grey, cmap=cm.Greys_r)
    subplot(223); imshow(threshold, cmap=cm.Greys_r)
    subplot(224); imshow(skeleton, cmap=cm.Greys_r)
    show()
    

    enter image description here

    您可能会发现其他引用骨架化的答案很有用,例如:

    Problems during Skeletonization image for extracting contours

相关问题