2015-04-28 69 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. 

我希望它會幫助你