How can I get a full medial-axis line with its perpendicular lines crossing it?

不想你离开。 提交于 2019-12-06 13:17:06

问题


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


回答1:


I think your question is slightly ill-posed. You have two questions here, but I'll answer the second one.

You want to draw lines perpendicular to the medial axis. The problem with that is the medial axis isn't necessarily a line, it is usually curved.

Your best bet is to take 2 sample points from the medial axis that are close to one another. These two points define a line. You can then compute the perpendicular bisector of these two points.



来源:https://stackoverflow.com/questions/13407470/how-can-i-get-a-full-medial-axis-line-with-its-perpendicular-lines-crossing-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!