Gray-weighted distance transform of grayscale image
Create a magic square. Matrices generated by the magic function have equal row, column, and diagonal sums. The minimum path between the upper-left and lower-right corner is along the diagonal.
A = magic(3)
A = 3×3 8 1 6 3 5 7 4 9 2
Calculate the gray-weighted distance transform, specifying the upper left corner and the lower right corner of the square as seed locations.
T1 = graydist(A,1,1); T2 = graydist(A,3,3);
Sum the two transforms to find the minimum path between the seed locations. As expected, there is a constant-value minimum path along the diagonal.
T = T1 + T2
T = 3×3 10 11 17 13 10 13 17 17 10
I— Grayscale image
Grayscale image, specified as a numeric or logical array.
mask— Binary mask
Binary mask that specifies seed locations, specified as a logical array the same
R— Column and row coordinates
Column and row coordinates of seed locations, specified as a vector of positive
integers. Coordinate values are valid
Indices of seed locations, specified as a vector of positive integers.
method— Distance metric
Distance metric, specified as one of these values.
In 2-D, the chessboard distance between (x1,y1) and (x2,y2) is
max(│x1 – x2│,│y1 – y2│).
In 2-D, the cityblock distance between (x1,y1) and (x2,y2) is
│x1 – x2│ + │y1 – y2│
In 2-D, the quasi-Euclidean distance between (x1,y1) and (x2,y2) is
For more information, see Distance Transform of a Binary Image.
T— Gray-weighted distance transform
Gray-weighted distance transform, returned as a numeric array of the same size as
I. If the input numeric type of
double, then the output numeric type of
double. If the input is any other numeric type, then the output
graydist uses the geodesic time algorithm . The basic equation for geodesic
time along a path is:
method determines the chamfer weights that are assigned to the local
neighborhood during outward propagation. Each pixel's contribution to the geodesic time is
based on the chamfer weight in a particular direction multiplied by the pixel
 Soille, P. "Generalized geodesy via geodesic time." Pattern Recognition Letters. Vol.15, December 1994, pp. 1235–1240.