[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

| Distance Transform |

## Functions

template<... >
void | distanceTransform (...)

## Detailed Description

Perform a distance transform using either the Euclidean, Manhattan, or chessboard metrics.

See also: multi-dimensional distance transforms

## Function Documentation

template<... >
void vigra::distanceTransform | ( |  | ... | ) |

For all background pixels, calculate the distance to the nearest object or contour. The label of the pixels to be considered background in the source image is passed in the parameter 'background'. Source pixels with other labels will be considered objects. In the destination image, all pixels corresponding to background will be assigned the their distance value, all pixels corresponding to objects will be assigned 0.

The parameter 'norm' gives the distance norm to be used:

- norm == 0: use chessboard distance (L-infinity norm)
- norm == 1: use Manhattan distance (L1 norm)
- norm == 2: use Euclidean distance (L2 norm)

If you use the L2 norm, the destination pixels must be real valued to give correct results.

Declarations:

pass arguments explicitly:

        namespace vigra {
            template <class SrcImageIterator, class SrcAccessor,
                               class DestImageIterator, class DestAccessor,
                               class ValueType>
            void distanceTransform(SrcImageIterator src_upperleft,
                            SrcImageIterator src_lowerright, SrcAccessor sa,
                            DestImageIterator dest_upperleft, DestAccessor da,
                            ValueType background, int norm)
        }

use argument objects in conjunction with Argument Object Factories :

        namespace vigra {
            template <class SrcImageIterator, class SrcAccessor,
                               class DestImageIterator, class DestAccessor,
                               class ValueType>
            void distanceTransform(
                triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
                pair<DestImageIterator, DestAccessor> dest,
                ValueType background, int norm)
        }

Usage:

#include <vigra/distancetransform.hxx>
Namespace: vigra

        vigra::BImage src(w,h), edges(w,h);
        vigra::FImage distance(w, h);

        // empty edge image
        edges = 0;
        ...

        // detect edges in src image (edges will be marked 1, background 0)
        vigra::differenceOfExponentialEdgeImage(srcImageRange(src), destImage(edges),
                                         0.8, 4.0);

        // find distance of all pixels from nearest edge
        vigra::distanceTransform(srcImageRange(edges), destImage(distance),
                                 0,                   2);
        //                       ^ background label   ^ norm (Euclidean)

Required Interface:

        SrcImageIterator src_upperleft, src_lowerright;
        DestImageIterator dest_upperleft;

        SrcAccessor sa;
        DestAccessor da;

        ValueType background;
        float distance;

        sa(src_upperleft) != background;
        da(dest_upperleft) < distance;
        da.set(distance, dest_upperleft);

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python VIGRA 1.6.0 (13 Aug 2008)