Contenuto principale

bwdistgeodesic

Geodesic distance transform of binary image

Description

D = bwdistgeodesic(BW,seedMask) calculates the geodesic distance transform D of the binary image BW. The binary image seedMask specifies the seed pixels.

The geodesic distance transform measures the length of the shortest path between each true pixel in BW and the nearest seed pixel. The transform constrains the path to stay within valid (true-valued) regions in BW.

D = bwdistgeodesic(BW,C,R) calculates the geodesic distance transform D, given valid regions specified by the 2-D binary image BW. The column and row coordinates C and R, respectively, specify the seed pixels.

example

D = bwdistgeodesic(BW,idx) calculates the geodesic distance transform D given valid regions specified by the binary image BW. The linear indices idx specify the seed pixels.

D = bwdistgeodesic(___,method) specifies an alternate distance metric, method, for the geodesic distance transform in addition to any combination of input arguments from previous syntaxes..

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 distances 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 = 10×10 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

Input Arguments

collapse all

Binary image, specified as a logical array of any dimension.

Regions where BW is true represent valid regions that can be traversed. Regions where BW is false represent regions that cannot be traversed.

Data Types: logical

Seed locations, specified as a logical array of the same size as BW. Each value of 1 (true) indicates a seed pixel.

Column coordinates of seed locations, specified as a vector of positive integers of the same length as R. To specify this argument, the binary image BW must be a 2-D matrix.

Row coordinates of seed locations, specified as a vector of positive integers of the same length as C. To specify this argument, the binary image BW must be a 2-D matrix.

Linear indices of seed locations, specified as a vector of positive integers.

Distance metric, specified as one of the following.

Distance Metric

Description

"chessboard"

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

max(abs(x1-x2),abs(y1-y2))

"cityblock"

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

abs(x1-x2) + abs(y1-y2)

"quasi-euclidean"

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

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

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

Data Types: char | string

Output Arguments

collapse all

Geodesic distances, returned as a numeric array of the same size as BW.

The false pixels in BW have undefined geodesic distances and the bwdistgeodesic function returns the value NaN for those pixels. If no path exists between a true pixel in BW and a seed pixel, then the bwdistgeodesic function returns the value Inf for that pixel.

Data Types: single

References

[1] Soille, Pierre. Morphological Image Analysis: Principles and Applications. 2nd ed. 219–21. Heidelberg: Springer Berlin, 2004.

Version History

Introduced in R2011b

See Also

|