如何获得一个完整的中轴线与其垂直线交叉? [英] How can I get a full medial-axis line with its perpendicular lines crossing it?

查看:455
本文介绍了如何获得一个完整的中轴线与其垂直线交叉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图像,我想得到穿过其中轴的像素。
我试图使用 skeletonize medial axis 方法为了得到它们,但是这两个方法返回比对应的对象更短的一维线。

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

正如你可以看到黑线没有连接到形状的顶端。

(1)如何获得完全连接的一维中轴线,代表

(2)如何获取垂直于中轴的像素(因为我想从一侧绘制垂直线到另一侧的垂直线穿过图像中的中轴形状)

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)


  • 我需要任何可以执行此操作的python库。

感谢

推荐答案

我认为你的问题略有不适。这里有两个问题,但我会回答第二个问题。

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.

这篇关于如何获得一个完整的中轴线与其垂直线交叉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆