简体   繁体   English

拟合曲线到分割图像

[英]Fit curve to segmented image

In my current data analysis I have some segmented Images like for example below. 在我目前的数据分析中,我有一些分段图像,例如下面。

My Problem is that I would like to fit a polynom or spline (s.th. one-dimensional) to a certain area (red) in the segmented image. 我的问题是我想在分割图像中将多项式或样条(s.th. one-dimensional)拟合到某个区域(红色)。 ( the result would be the black line). (结果将是黑线)。

Usually i would use something like orthogonal distance regression, the problem is that this needs some kind of fit function which I don't have in this case. 通常我会使用像正交距离回归这样的东西,问题是这需要某种拟合函数,在这种情况下我没有。 So what would be the best approach to do this with python/numpy? 那么使用python / numpy执行此操作的最佳方法是什么? Is there maybe some standard algorithm for this kind of problem? 对于这种问题,是否有一些标准算法?

例

UPDATE: it seems my drawing skills are probably not the best, the red area in the picture could also have some random noise and does not have to be completely connected (there could be small gaps due to noise). 更新:看起来我的绘图技巧可能不是最好的,图片中的红色区域也可能有一些随机噪音而且不必完全连接(由于噪音可能会有小间隙)。

UPDATE2: The overall target would be to have a parametrized curve p(t) which returns the position ie p(t) => (x, y) for t in [0,1]. 更新2:总体目标是具有参数化曲线p(t),其返回[0,1]中t的位置,即p(t)=>(x,y)。 where t=0 start of black line, t= 1 end of black line. 其中t = 0开始黑线,t = 1黑线结束。

I used scipy.ndimage and this gist as a template. 我用scipy.ndimage这个要点作为模板。 This gets you almost there, you'll have to find a reasonable way to parameterize the curve from the mostly skeletonized image. 这让你几乎到了那里,你将不得不找到一种合理的方法来从大多数骨架化的图像中参数化曲线。

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()

在此输入图像描述

You may find other answers that reference skeletonization useful, an example of that is here: 您可能会发现其他引用骨架化的答案很有用,例如:

Problems during Skeletonization image for extracting contours 用于提取轮廓的骨架化图像中的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM