vigra - Distance Transform

[ 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

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 2D array views:

namespace vigra {
template <class T1, class S1,
class T2, class S2,
class ValueType>
void
distanceTransform(MultiArrayView<2, T1, S1> const & src,
MultiArrayView<2, T2, S2> dest,
ValueType background, int norm);
}

show deprecated declarations

pass Image Iterators and Data Accessors :
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

MultiArray<2, unsigned char> src(w,h), edges(w,h);
MultiArray<2, float> distance(w, h);
...
// detect edges in src image (edges will be marked 1, background 0)
differenceOfExponentialEdgeImage(src, edges, 0.8, 4.0);
// find distance of all pixels from nearest edge
distanceTransform(edges, distance, 0, 2);
// ^ background label ^ norm (Euclidean)

show deprecated examples

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);

Examples:
  voronoi.cxx.

© 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.10.0 (Mon Nov 18 2013)