IPSDK 0.2
IPSDK : Image Processing Software Development Kit
Distance Map 2dSee full documentation
imagedistanceMap2dImg (inBinImg)
imagedistanceMap2dImg (inBinImg,maxDistance)

Detailed Description

Algorithm for distance map transform computation of an input binary image.

Distance map algorithm, also called distance transform, allows to compute exact euclidian distance for each set pixel (with intensity set to 1) to the nearest boundary (nearest zero pixel) in a binary image. If the parameter $ maxDistance $ is provided, the propagation is constrained so that it stops when the distance is higher than the $ maxDistance $ value.

Resulting image buffer type must be one of the following :

Output image values are given by :

\[ OutDistImg[x, y] = \left\{\begin{matrix} 0 \; if \; InBinImg[x, y] = 0 \\ \min\limits_{(x', y') / InBinImg[x', y'] = 1} {norm_{2}(x, y, x', y')} \; else \end{matrix}\right. \]

where $ norm_{2} $ stands for euclidian norm :

\[ norm_{2}(x, y, x', y') = \Arrowvert \begin{pmatrix} x \\ y \end{pmatrix} - \begin{pmatrix} x' \\ y' \end{pmatrix} \Arrowvert_{2} \]

Here is an example of a distance map 2d computation applied to a binary input image with an unsigned int 16 result image :

distanceMap2dImg.png
Note
A real 32 image can be used as output to avoid distance rounding approximation associated to integer output data type.
See also
http://en.wikipedia.org/wiki/Distance_transform

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLBasicMorphology as morpho

Code Example

# opening of input image
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
# distance map 2d computation
outImg = morpho.distanceMap2dImg(inImg)

Example of C++ code :

Example informations

Header file

#include <IPSDKIPL/IPSDKIPLBasicMorphology/Processor/DistanceMap2dImg/DistanceMap2dImg.h>

Code Example

// opening input image
ImagePtr pInBinImg = loadTiffImageFile(inputImgPath);
// define output image geometry
ImageGeometryPtr pGeometry = geometry2d(outputImageBufferType,
pInBinImg->getSizeX(),
pInBinImg->getSizeY());
// creation of output image
boost::shared_ptr<MemoryImage> pOutDistImg(boost::make_shared<MemoryImage>());
pOutDistImg->init(*pGeometry);
// compute distance map on input image
distanceMap2dImg(pInBinImg, pOutDistImg);