[mmopen] [Up] [mmgdist] Image Transforms

mmdist
Distance transform.

Synopsis

function y = mmdist ( f , Bc , METRIC )

Input

f Image Binary image
Bc Structuring Element

Default: 3x3 elementary cross

(connectivity)

METRIC String

Default: NULL

'EUCLIDEAN', or 'EUC2' for squared Euclidean.

Output

y Image

distance image in uint16, or in int32 datatype with EUC2 option.

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

Examples

Simple numeric example
a = mmframe(mmbinary(ones(5,9)),2,4)
Warning: converting image from double to int32
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
f mod(double(d4),8) mod(double(d8),8) mod(double(de),8)

Equation

distance of a point x to a set X:
distance function:
distance function using structuring element:
Relationship between erosion and distance transform:

Algorithm

function g = mmdist_equ(f,Bc)
z = mmbinary([0]);
g = mmgray(f,'uint8',1);
ero = f;
while ~mmisequal(ero,z)
  ero = mmero(ero,Bc);
  g = mmaddm(g,mmgray(ero,'uint8',1));
end

Limitations

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. Use the option EUC2 to compute exact squared Euclidean distance transform.

See also

mmfreedom Control automatic data type conversion.
mmdtshow Display a distance transform image with an iso-line color table.
mmero Erode an image by a structuring element.
mmgdist Geodesic Distance Transform.
mmsebox Create a box structuring element.
mmsecross Diamond structuring element and elementary 3x3 cross.
[mmopen] [Up] [mmgdist]