jrs*_*rsm 6 python numpy scipy
在我目前的数据分析中,我有一些分段图像,例如下面.
我的问题是我想在分割图像中将多项式或样条(s.th. one-dimensional)拟合到某个区域(红色).(结果将是黑线).
通常我会使用像正交距离回归这样的东西,问题是这需要某种拟合函数,在这种情况下我没有.那么用python/numpy执行此操作的最佳方法是什么?对于这种问题,是否有一些标准算法?
更新:看起来我的绘图技巧可能不是最好的,图片中的红色区域也可能有一些随机噪音而且不必完全连接(由于噪音可能会有小间隙).
更新2:总体目标是具有参数化曲线p(t),其返回[0,1]中t的位置,即p(t)=>(x,y).其中t = 0开始黑线,t = 1黑线结束.
我使用scipy.ndimage
这个要点作为模板。这让你几乎到了那里,你必须找到一种合理的方法来参数化大部分骨架图像的曲线。
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()
Run Code Online (Sandbox Code Playgroud)
您可能会发现其他参考骨架化有用的答案,示例如下:
归档时间: |
|
查看次数: |
1146 次 |
最近记录: |