# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

# graydist

Gray-weighted distance transform of grayscale image

## Syntax

T = graydist(A,C,R)
T = graydist(A,ind)
T = graydist(...,method)

## Description

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

T = graydist(A,C,R) uses vectors C and R to specify the row and column coordinates of seed locations.

T = graydist(A,ind) specifies the linear indices of seed locations using the vector ind.

T = graydist(...,method) specifies an alternate distance metric. 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.

## Input Arguments

A

Grayscale image.

Logical image the same size as A that specifies seed locations.

C,R

Numeric vectors that contain the positive integer row and column coordinates of the seed locations. Coordinate values are valid C,R subscripts in A.

ind

Numeric vector of positive integer, linear indices of seed locations.

method

Type of distance metric. method can have any of these values.

MethodDescription

'cityblock'

In 2-D, the cityblock distance between (x1,y1) and (x2,y2) is x1x2│ + │y1y2.

'chessboard'

The chessboard distance is
max(│x1x2│,│y1y2│).

'quasi-
euclidean'

The quasi-Euclidean distance is

Default: 'chessboard'

## Output Arguments

 T Array the same size as A that specifies the gray-weighted distance transform. If the input numeric type of A is double, the output numeric type of T is double. If the input is any other numeric type, the output T is single.

## Class Support

A can be numeric or logical, and it must be nonsparse. mask is a logical array of the same size as A. C, R, and ind are numeric vectors that contain positive integer values.

The output T is an array of the same size as A. If the input numeric type of A is double, the output T is double. If the input is any other numeric type, the output T is single.

## 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 =

8     1     6
3     5     7
4     9     2

Calculate the gray-weighted distance transform, specifing 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 =

10    11    17
13    10    13
17    17    10

## Algorithms

graydist uses the geodesic time algorithm described in Soille, P., Generalized geodesy via geodesic time,, Pattern Recognition Letters, vol.15, December 1994; pp. 1235–1240

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)$