# mmgdist
Geodesic Distance Transform.

## Synopsis

y = mmgdist( f, g, Bc = None, METRIC = None )

Implemented in Python.

### Input

f | Image Binary image.
g | Image Binary image. Marker image
Bc | Structuring Element (metric for distance). Default: `None` (3x3 elementary cross)
METRIC | String 'EUCLIDEAN' if specified. Default: `None`

### Output

y | Image uint16 (distance image).

## Description

mmgdist creates the geodesic distance image `y` of the binary image `f` relative to the binary image `g`. The value of `y` at the pixel `x` is the length of the smallest path between `x` and `f`. The distances available are based on the Euclidean metrics and on metrics generated by a neighbourhood graph, that is characterized by a connectivity rule defined by the structuring element `Bc`. The connectivity for defining the paths is consistent with the metrics adopted to measure their length. In the case of the Euclidean distance, the space is considered continuos and, in the other cases, the connectivity is the one defined by `Bc`.

## Examples

    >>> f=mmbinary([
     [1,1,1,1,1,1],
     [1,1,1,0,0,1],
     [1,0,1,0,0,1],
     [1,0,1,1,0,0],
     [0,0,1,1,1,1],
     [0,0,0,1,1,1]])

    >>> g=mmbinary([
     [0,0,0,0,0,0],
     [1,1,0,0,0,0],
     [0,0,0,0,0,0],
     [0,0,0,0,0,0],
     [0,0,0,0,0,0],
     [0,0,0,0,0,1]])

    >>> y=mmgdist(f,g,mmsecross())

    >>> print y

    [[    1     1     2     3     4     5]
     [    0     0     1 65535 65535     6]
     [    1 65535     2 65535 65535     7]
     [    2 65535     3     4 65535 65535]
     [65535 65535     4     3     2     1]
     [65535 65535 65535     2     1     0]]

    >>> f=mmreadgray('maze_bw.tif')

    >>> g=mmintersec(f,0)

    Warning: Converting input image from int32 to binary uint8.

    >>> g=mmdrawv(g,uint16([[2],[2],[6],[6]]),uint16(1),'frect')

    >>> y=mmgdist(f,g,mmsebox(),'EUCLIDEAN')

    >>> mmshow(f,g)

    >>> mmdtshow(y,200)

f,g | y,200 |

## Equation

geodesic distance function using structuring element:

## Limitations

To generate useful Distance transforms, the structuring elements must be symmetric and with the origin included. The Euclidean Distance transform is rounded to the nearest integer, since it is represented in an unsigned integer image. You should use the `mmsebox` structuring element when computing the Euclidean Distance transform.

## Source Code

    def mmgdist(f, g, Bc=None, METRIC=None):
        if Bc is None: Bc = mmsecross()
        assert METRIC is None,'Does not support EUCLIDEAN'
        fneg,gneg = mmneg(f),mmneg(g)
        y = mmgray(gneg,'uint16',1)
        ero = mmintersec(y,0)
        aux = y
        i = 1
        while not mmisequal(ero,aux):
            aux = ero
            ero = mmcero(gneg,fneg,Bc,i)
            y = mmaddm(y,mmgray(ero,'uint16',1))
            i = i + 1
        y = mmunion(y,mmgray(ero,'uint16'))
        return y

## See also

mmdist | Distance transform.
mmsecross | Diamond structuring element and elementary 3x3 cross.
mmsebox | Create a box structuring element.
mmfreedom | Control automatic data type conversion.
mmcero | Erode an image conditionally.

[`mmdist`] [Up] [`mmopentransf`] |
Copyright (c) 2003, Roberto A. Lotufo, UNICAMP-University of Campinas; Rubens C. Machado, CenPRA-Renato Archer Research Center.