2016-06-15 94 views
0

我需要帮助,试图找出确定从已知点到网络边缘距离的matlab代码,如图binary image of angiogenesis from a bead所示。我知道前面的代码的确切点,但我要求帮助确定从该点到图像中出现的任何主要边缘的距离。任何想法或意见将不胜感激。谢谢!从已知点到网络边缘的距离

+0

您可以使用t他距离公式'dist = sqrt((y2-y1)^ 2 +(x2-x1)^ 2); %%%%'其中'(x1,y1)'和'(x2,y2)'是两个坐标像素 – Altronicx

回答

0

使用MATLAB的边缘函数检测图像中的边缘,使用bwdist函数计算边缘的距离变换。 距离变换图像基本上是一张图,它在每个像素处包含它与输入图像中白色像素的距离(在我们的例子中,这些是图像的边缘)。

代码

计算距离变换地图

distMap = bwdist(edge(I)); 

从I的边缘确定点P =(X,Y)的距离:

distFromP = distMap(y,x) 

一个班轮解决方案

通过使用method suggested in this answer有可能产生用于从I的边缘计算点P =(X,Y)的距离的一行代码:

distFromP = subsref(bwdist(edges(I)),struct('type','()','subs',{{y,x}})); 

指定距离方法

您还可以通过传递方法参数(默认方法为Euclidian)来指定您希望使用的距离函数,如以下示例中所示:

D1 = bwdist(im,'euclidean'); %euclidian distance sqrt(|y1-y2|^2+|x1-x2|^2) 
D2 = bwdist(im,'cityblock'); %city block distance (|y1-y2|+|x1-x2|) 
D3 = bwdist(im,'chessboard'); %chessboard (max(|y1-y2|,|x1-x2|) 
D4 = bwdist(im,'quasi-euclidean'); %quasi-euclidean (for more information see MATLAB's documentation)