| [Top] [Up] [Prev] [Next] | [Up] [Tutorial] | mmtutor V1.0 30abr2001 |
mm090distance A distance or metric d must satisty conditions:
The first condition says that the distance is non-negative value. If the distance between two points is zero, then these two points are at the same location. The second condition says that the distance for going from one point to another is the same as returning distance. Finally, the third condition says that when going from one point to another, if stoping at a third point in between, the overall distance can never be less than going non-stop.
A distance n from a point or region can be determined by dilating the point or region by the str. el. nB. B gives the metric used. B is any symetrical str. el. with the origin.
The 8-connected distance (chessboard) can be generated by the elementary 3x3 square. Below a disk of radius 5 is generated.
str1=mmsebox(1); A=mmseshow(str1,'EXPAND'); mmshow(A); ; str2=mmsesum(str1,5); B=mmseshow(str2,'EXPAND'); ; mmshow(B); ;
|
The 4-connected distance (city-block) can be generated by the elementary 3x3 cross. Below a disk of radius 5 is generated.
str1=mmsecross(1); C=mmseshow(str1,'EXPAND'); mmshow(C); ; str2=mmsesum(str1,5); D=mmseshow(str2, 'EXPAND'); mmshow(D); ;
|
The distance from any object pixel to the background can be computed by the Distance Transform DT. You can choose the metric using in the DT. Three metrics are used below: city-block, chessboard and Euclidean. The Euclidean is not a discrete metric and the str. el. to define the neighborhood depends on the maximum possible distance on the image.
A=imread('blob3.tif');
mmshow(A);
d4=mmdist(A,mmsecross);
mmshow(d4);
d8=mmdist(A,mmsebox);
mmshow(d8);
de=mmdist(A,mmsebox,'EUCLIDEAN');
mmshow(de);
|
The distance from a region can be computed by taking the Distance Transform of the background. Below, we compute the distance using three different metrics: city-block, using the elementary cross str. el., chessboard, using the elementary square, and a vertical distance using a 1x3 structuring element.
The geodesic distance is a distance more familiar to our daily activities. The distance from our home to work is not a straight line, rather the paths available are restricted. In this sense the distance is the shortest path in all possible paths availables. The geodesic distance can be computed by the geodesic dilation.
Below is an illustration where the restriction is given by a region in the shape of the letter G. We want to compute all the geodesic distances from any point in G to a given point.
A=imread('gletter.tif');
mmshow(A);
B=mmsubm(A,A);
B(62,78)=1;
B=mmdil(B,mmsedisk(1));
mmshow(A,B);
C=mmgdist(A,B,mmsebox,'EUCLIDEAN');
mmdtshow(C,20);
|
To find the shortest geodesic path between two points, we can use the property that the sum of the distances to both points is minimal in the shortest path. So, we can process the following steps:
Below is a simple demonstration to compute the shortest path from one place to another in a map. Suppose that the white pixels in the map are the only places that a path can exists. First compute the geodesic distance from each points.
A=imread('mapacampus_bw.tif');
img=mmsubm(A,A);
P1=img; P2=img;
P1(26,94)=1;
P2(300,290)=1;
P1=mmdil(P1,mmsedisk(2));
P2=mmdil(P2,mmsedisk(2));
mmshow(A,P1,P2);
B=mmgdist(A,P1,mmsebox,'EUCLIDEAN');
mmdtshow(B,80);
C=mmgdist(A,P2,mmsebox,'EUCLIDEAN');
mmdtshow(C,80);
|
Next, add both distances and compute the places of the minimum values. The shortest path is overalayed in red.
D=mmaddm(B,C); mmdtshow(D,400); d=mmstats(D,'min') d = 389 res=mmcmp(D,'<=', uint16(d+1)); mmshow(A,res);
|
f=imread('touchcell.tif');
mmshow(f);
|
| [Top] [Up] [Prev] [Next] | [Up] [Tutorial] |
|
| Copyright (c) 1998-20001 by SDC Information SystemsCopyright (c) 1998-20001 by SDC Information Systems | ||