2016-06-15 92 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)