我怎样才能获得与它的垂直线的交叉是一个完整的中间轴线?(How can I get a full m

2019-08-02 19:47发布

I have an image and I want to get the pixels that cross through its medial axis. I tried to use skeletonize and medial axis methods in order to get them but both methods return one dimensional line which is shorter than the corresponding object.

Here's the code with a sample image:-

>>> import skimage.filter  
>>> import skimage.morphology  
>>> import numpy as np  
>>> import scipy.misc
>>> im=scipy.misc.imread('img.jpg')   
>>> thr=skimage.filter.threshold_otsu(im)  
>>> im=im > thr # Threshold the image  
>>> im_sk=skimage.morphology.skeletonize(im)  
>>> mask=np.where(im_sk==1)     # pixels of skeleton  
>>> im[mask]= 0                 # this will color the skeleton with black  

Original >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Result
or_im http://imageshack.us/a/img23/9035/testwus.jpg sk_im http://imageshack.us/a/img585/1910/imgskx.jpg

As you can see the black line isn't connected to the tip of the shape.
(1) How can I get a fully connected one dimensional medial axis line that represents the length of the shapes in the image.
(2) How can I get the pixels that are perpendicular to the medial axis (as I want to draw perpendicular lines from one side to another crossing the medial axis of the shape)

  • I need any python library that can do this stuff.

Thanks

Answer 1:

我觉得你的问题稍微病态。 你有两个问题在这里,但我会回答第二个。

要绘制垂直于中轴线。 与该问题是中轴不一定是线,它通常是弯曲的。

最好的办法是从中轴是接近彼此取2个样点。 这两点确定一条线。 然后,您可以计算出这两点的垂直平分线。



文章来源: How can I get a full medial-axis line with its perpendicular lines crossing it?