graydist

Gray-weighted distance transform of grayscale image

Description

T = graydist(I,mask) computes the gray-weighted distance transform of the grayscale image I. Locations where mask is true are seed locations.

example

T = graydist(I,C,R) specifies the column and row coordinates of seed locations in vectors C and R.

T = graydist(I,ind) specifies the linear indices of seed locations, ind.

T = graydist(___,method) specifies an alternate distance metric, method.

Examples

collapse all

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

Input Arguments

collapse all

Grayscale image, specified as a numeric or logical array.

Binary mask that specifies seed locations, specified as a logical array the same size as I.

Column and row coordinates of seed locations, specified as a vector of positive integers. Coordinate values are valid C,R subscripts in I.

Indices of seed locations, specified as a vector of positive integers.

Distance metric, specified as one of these values.

Method

Description

'chessboard'

In 2-D, the chessboard distance between (x1,y1) and (x2,y2) is

max(│x1x2│,│y1y2│).

'cityblock'

In 2-D, the cityblock distance between (x1,y1) and (x2,y2) is

x1x2│ + │y1y2

'quasi-euclidean'

In 2-D, the quasi-Euclidean distance between (x1,y1) and (x2,y2) is

Output Arguments

collapse all

Gray-weighted distance transform, returned as a numeric array of the same size as I. If the input numeric type of I is double, then the output numeric type of T is double. If the input is any other numeric type, then the output T is single.

Data Types: single | double

Algorithms

graydist uses the geodesic time algorithm . The basic equation for geodesic time along a path is:

${\tau }_{f}\left(P\right)=\frac{f\left({p}_{o}\right)}{2}+\frac{f\left({p}_{l}\right)}{2}+\sum _{i=1}^{l-1}f\left({p}_{i}\right)$

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 intensity.

 Soille, P. "Generalized geodesy via geodesic time." Pattern Recognition Letters. Vol.15, December 1994, pp. 1235–1240.