I need help trying to figure out the matlab code for determination of the distance from a known point to the edges of the web seen in this figure binary image of angiogenesis from a bead. I know the precise point from previous code but I request any help in determination of the the distance from this point to any major edges seen in the image. Any ideas or input would be appreciated. Thank you!
-
You could just use the distance formula `dist=sqrt((y2-y1)^2+(x2-x1)^2);%%%%` Where `(x1,y1)` and `(x2,y2)` are coordinates of two pixels – Altronicx Jun 15 '16 at 01:14
1 Answers
use MATLAB's edge function to detect edges in the image, and bwdist function to calculate the distance transform from the edges. The distance transform image is basically a map, which contains at each pixel it's distance from the white pixels in the input image (in our case these are the edges of the image).
Code
Calculate the distance transform map
distMap = bwdist(edge(I));
Determine the distance of point P=(x,y) from the edges of I:
distFromP = distMap(y,x)
One Liner solution
By using the method suggested in this answer it is possible to generate a one line code for calculating the distance of point P=(x,y) from the edges of I:
distFromP = subsref(bwdist(edges(I)),struct('type','()','subs',{{y,x}}));
Specifying distance method
You can also specify the distance function which you would like to use, by passing a method parameter (the default method is Euclidian), as can be seen in the following examples:
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)