How can I get a full medial-axis line with its per

2019-04-14 21:36发布

问题:

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.