Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

bwdistgeodesic

Geodesic distance transform of binary image

Syntax

D = bwdistgeodesic(BW,mask)
D = bwdistgeodesic(BW,C,R)
D = bwdistgeodesic(BW,ind)
D = bwdistgeodesic(...,method)

Description

D = bwdistgeodesic(BW,mask) computes the geodesic distance transform, given the binary image BW and the seed locations specified by mask. Regions where BW is true represent valid regions that can be traversed in the computation of the distance transform. Regions where BW is false represent constrained regions that cannot be traversed in the distance computation. For each true pixel in BW, the geodesic distance transform assigns a number that is the constrained distance between that pixel and the nearest true pixel in mask. Output matrix D contains geodesic distances.

D = bwdistgeodesic(BW,C,R) computes the geodesic distance transform of the binary image BW. Vectors C and R contain the column and row coordinates of the seed locations.

D = bwdistgeodesic(BW,ind) computes the geodesic distance transform of the binary image BW. ind is a vector of linear indices of seed locations.

D = bwdistgeodesic(...,method) specifies an alternate distance metric.

Input Arguments

BW

Binary image.

mask

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

C,R

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

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

|x1x2|+(21)|y1y2|, |x1x2|>|y1y2|

(21)|x1x2|+|y1y2|, otherwise.

Default: 'chessboard'

Output Arguments

D

Numeric array of class single, with the same size as input BW, that contains geodesic distances.

Class Support

BW is a logical matrix. C, R, and ind are numeric vectors that contain positive integer values. D is a numeric array of class single that has the same size as the input BW.

Examples

collapse all

Create a sample binary image for this example.

BW = [1 1 1 1 1 1 1 1 1 1;...
     1 1 1 1 1 1 0 0 1 1;...
     1 1 1 1 1 1 0 0 1 1;...
     1 1 1 1 1 1 0 0 1 1;...
     0 0 0 0 0 1 0 0 1 0;...
     0 0 0 0 1 1 0 1 1 0;...
     0 1 0 0 1 1 0 0 0 0;...
     0 1 1 1 1 1 1 0 1 0;...
     0 1 1 0 0 0 1 1 1 0;...
     0 0 0 0 1 0 0 0 0 0];
 BW = logical(BW);

Create two vectors of seed locations.

C = [1 2 3 3 3];
R = [3 3 3 1 2];

Calculate the geodesic distance transform. Output pixels for which BW is false have undefined geodesic distance and contain NaN values. Because there is no connected path from the seed locations to element BW(10,5), the output D(10,5) has a value of Inf.

D = bwdistgeodesic(BW,C,R)
D = 10x10 single matrix

     2     1     0     1     2     3     4     5     6     7
     1     1     0     1     2     3   NaN   NaN     6     7
     0     0     0     1     2     3   NaN   NaN     7     7
     1     1     1     1     2     3   NaN   NaN     8     8
   NaN   NaN   NaN   NaN   NaN     3   NaN   NaN     9   NaN
   NaN   NaN   NaN   NaN     4     4   NaN    10    10   NaN
   NaN     8   NaN   NaN     5     5   NaN   NaN   NaN   NaN
   NaN     8     7     6     6     6     6   NaN     8   NaN
   NaN     8     7   NaN   NaN   NaN     7     7     8   NaN
   NaN   NaN   NaN   NaN   Inf   NaN   NaN   NaN   NaN   NaN

Algorithms

bwdistgeodesic uses the geodesic distance algorithm described in Soille, P., Morphological Image Analysis: Principles and Applications, 2nd Edition, Secaucus, NJ, Springer-Verlag, 2003, pp. 219–221.

See Also

|

Introduced in R2011b

Was this topic helpful?