【问题标题】:Fit curve to segmented image将曲线拟合到分割图像
【发布时间】:2014-05-16 04:03:55
【问题描述】:

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

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

通常我会使用正交距离回归之类的东西,问题是这个 需要某种我在这种情况下没有的拟合功能。 那么使用 python/numpy 执行此操作的最佳方法是什么? 这类问题可能有一些标准算法吗?

更新: 看来我的绘画技术可能不是最好的,图片中的红色区域也可能有一些随机噪声并且不必完全连接(由于噪声可能存在小间隙)。

更新2: 总体目标是有一个参数化的曲线 p(t),它返回位置,即 p(t) => (x, y) for t in [0,1]。其中t=0黑线起点,t=1黑线终点。

【问题讨论】:

  • 您需要进行试验,但您需要的一切都应该在skimage.morphology 中提供。我猜你会想要在将其转换为二进制图像之前或之后使用closing 来消除噪声,可能是通过阈值处理,然后是skeletonize
  • 假设我从我的数组中得到一个可接受的骨架。获得多项式/样条线的下一步是什么。
  • 如果您要做更复杂的事情,值得查看 Stack Exchange 站点 dsp.stackexchange.com

标签: python numpy scipy


【解决方案1】:

我使用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()

您可能会发现其他参考骨架化有用的答案,这里有一个示例:

Problems during Skeletonization image for extracting contours

【讨论】:

  • 这似乎已经很好用了,我的想法是将骨架分成 N 段,并将其用作样条插值的节点,但我还不确定。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-30
相关资源
最近更新 更多