2015-04-28 17 views
3

我有一个存储为SVG中路径元素的2D形状。这些形状由贝塞尔曲线和线段组成。如何计算2D矢量形状的中轴?

我还有一组沿着形状的等距空间点,我使用弧长参数化生成 。

如何使用SVG或这些点来确定形状的中轴?

我使用Python,但任何形式的伪代码或算法的建议将不胜感激。


以下是类型我处理的形状的例子,红点是沿曲线我的采样点。

example

+0

你你提供一个例子形状为我们一起玩? – will

+0

当然,这里是上面的例子中使用的一个:http://hastebin.com/esiyojehik.svg 这里是沿着这个形状的点集:http://hastebin.com/usosaruyup.py – flutillie

+0

什么做你的意思是中轴吗?我的意思是你指的是经典的大惯性轴(http://www.mukimuki.fr/flashblog/2009/05/20/magic-moments/),或者是指一直处于形状中心的曲线它试图追随它的边界最终弯曲自然? –

回答

0

你可以看到从skimage(scikit图像)的代码。你会发现骨架以及用于中间轴(skimage.morphology.medial_axis)

源可在此地址的代码:https://github.com/scikit-image/scikit-image/blob/v0.12.2/skimage/morphology/_skeletonize.py#L103

该算法计算中轴变换的图像 作为它的距离变换的脊。

的不同步骤的算法如下

A lookup table is used, that assigns 0 or 1 to each configuration of 
    the 3x3 binary square, whether the central pixel should be removed 
    or kept. 

We want a point to be removed if it has more than one neighbor 
    and if removing it does not change the number of connected components. 


The distance transform to the background is computed, as well as 
    the cornerness of the pixel. 

The foreground (value of 1) points are ordered by 
    the distance transform, then the cornerness. 

A cython function is called to reduce the image to its skeleton. It 
    processes pixels in the order determined at the previous step, and 
    removes or maintains a pixel according to the lookup table. 

Because 
    of the ordering, it is possible to process all pixels in only one 
    pass. 

我希望它会帮助你