【问题标题】:Interpolate continuous curve from noisy data从噪声数据中插入连续曲线
【发布时间】:2021-07-08 13:50:18
【问题描述】:

我正在尝试从噪声数据(例如示例中的圆圈)中估计/插值曲线。我的数据不仅包含圆圈,但这也应该是解决其他结构的一个很好的起点。

我有一个嘈杂的二进制图像,我正在尝试为它拟合一条连续的曲线/骨架(如果形状不是圆形,每个像素都有 2 个邻居,除了可能的开始和结束像素)。 我在分别拟合 x,y 坐标方面取得了一些成功,将到起点的距离用作 x 值,将坐标用作 y 值,然后以小步长插值距离。然后我检查坐标是否全部连接。在某些极端情况下,新的插值点没有连接,我必须使用更小的步骤进行插值。这通常还会导致像素具有超过 2 个相邻像素和其他奇怪的伪影。

有没有更简单的方法可以将这些值拟合到曲线上并得到一条连续曲线?

import numpy as np
from skimage import draw
from matplotlib import pyplot as plt
image = np.zeros((200,200), dtype=np.uint8)

coords = np.array(draw.circle_perimeter(100,100,50))

noise = np.random.normal(0,2,coords.shape).astype(np.int64)

coords += noise
image[coords[0], coords[1]] = 1

plt.imshow(image, cmap="gray")

plt.show()

【问题讨论】:

    标签: python image-processing interpolation curve-fitting


    【解决方案1】:

    要拟合数据,您需要一个模型。拟合圆的方法有很多种。我最成功的一个是 Ian Coope 的线性化解决方案。该论文可在此处获得:https://ir.canterbury.ac.nz/handle/10092/11104

    我在一个名为scikit-guess 的线性拟合库中对其进行了python 实现。函数是skg.nsphere_fit。给定您的 (2, n) 数组 coords,您可以像这样使用它:

    from skg import nsphere_fit
    
    radius, center = nsphere_fit(coords, axis=0)
    

    要覆盖您的图像,您可以使用matplotlib.patches.Circle

    from matplotlib.patches import Circle
    
    fig, ax = plt.subplots()
    ax.imshow(image, cmap='gray')
    ax.add_patch(Circle(center[::-1], radius, edgecolor='red', facecolor='none'))
    

    您需要反转center,因为您的输入坐标是(row, col),而Circle 需要(x, y),即(col, row)

    要适应不同的模型,您需要不同的方法。对于任意模型,您可能需要查看 scipy.optimizelmfit

    【讨论】:

      【解决方案2】:

      为嘈杂的数据拟合一个圆圈非常简单:

      此方法来自https://fr.scribd.com/doc/14819165/Regressions-coniques-quadriques-circulaire-spherique

      【讨论】:

        猜你喜欢
        • 2013-06-16
        • 1970-01-01
        • 2016-06-07
        • 1970-01-01
        • 1970-01-01
        • 2018-05-21
        • 1970-01-01
        • 1970-01-01
        • 2016-10-19
        相关资源
        最近更新 更多