[Top] [Up] [Prev] [Next] [Up] [Basic Concepts] [Demonstrations] [Functions] SDC Morphology Toolbox V1.1 15Jan02

mmdist - Distance transform.


Synopsis
y = mmdist( f, Bc, METRIC )
Input
f: Binary image (logical uint8).
Bc: Structuring element. (connectivity) Default: Elementary cross (mmsecross).
METRIC: String. 'EUCLIDEAN' if specified. Default: No parameter.
Output
y: Gray-scale (uint8 or uint16) image. uint16 (distance image).
Description
mmdist creates the distance image y of the binary image f. The value of y at the pixel x is the distance of x to the complement of f, that is, the distance of x to nearest point in the complement of f. The distances available are based on the Euclidean metrics and on metrics generated by a a regular graph, that is characterized by a connectivity rule defined by the structuring element Bc. The implementation of the Euclidean algorithm is based on [LZ01] .
Limitation
To generate useful Distance transforms, the structuring elements must be symmetric and have the origin included. The Euclidean Distance transform is rounded to the nearest integer, since it is represented as an unsigned integer image.
Examples

Simple numeric example

a = mmframe(mmbinary(ones(5,9)),2,4)
Warning: Converting image from double to uint16.
a =
     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1
     1     1     1     1     0     1     1     1     1
     1     1     1     1     1     1     1     1     1
     1     1     1     1     1     1     1     1     1
f4=mmdist(a)

f4 =
     6     5     4     3     2     3     4     5     6
     5     4     3     2     1     2     3     4     5
     4     3     2     1     0     1     2     3     4
     5     4     3     2     1     2     3     4     5
     6     5     4     3     2     3     4     5     6
f8=mmdist(a,mmsebox)

f8 =
     4     3     2     2     2     2     2     3     4
     4     3     2     1     1     1     2     3     4
     4     3     2     1     0     1     2     3     4
     4     3     2     1     1     1     2     3     4
     4     3     2     2     2     2     2     3     4
fe=mmdist(a,mmsebox,'EUCLIDEAN')

fe =
     4     4     3     2     2     2     3     4     4
     4     3     2     1     1     1     2     3     4
     4     3     2     1     0     1     2     3     4
     4     3     2     1     1     1     2     3     4
     4     4     3     2     2     2     3     4     4

Image example

f = mmreadgray('gear.tif');
f = mmneg(mmgradm(f));
d4=mmdist(f);
d8=mmdist(f,mmsebox);
de=mmdist(f,mmsebox,'EUCLIDEAN');
mmshow(f);
mmshow(mod(double(d4),8));
Warning: Converting image from double to uint16.
mmshow(mod(double(d8),8));
Warning: Converting image from double to uint16.
mmshow(mod(double(de),8));
Warning: Converting image from double to uint16.
image
(f)
image
(mod(double(d4),8))
image
(mod(double(d8),8))
image
(mod(double(de),8))
Equation

distance of a point x to a set X:

equation

distance function:

equation

distance function using structuring element:

equation

Relationship between erosion and distance transform:

equation

Algorithm
function g = mmdist_equ(f,Bc)
z = logical(uint8(0));
g = mmgray(f,'uint8',1);
ero = f;
while ~mmisequal(ero,z)
  ero = mmero(ero,Bc);
  g = mmaddm(g,mmgray(ero,'uint8',1));
end
See Also
mmero - Erode an image by a structuring element.
mmfreedom - Control automatic data type conversion.
mmgdist - Geodesic Distance Transform.
mmsebox - Create a box structuring element.
mmsecross - Cross structuring element.

[Top] [Up] [Prev] [Next] [Up] [Basic Concepts] [Demonstrations] [Functions] Valid XHTML 1.0!
Copyright (c) 1998-2002 by SDC Information Systems