IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit

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

IPSDKIPLBASICMORPHOLOGY_API ipsdk::image::ImagePtr ipsdk::imaproc::morpho::distanceMap2dImg (const ipsdk::image::ImageConstPtr &pInBinImg)
 wrapper function for distance map transform of an input binary image More...
 
IPSDKIPLBASICMORPHOLOGY_API void ipsdk::imaproc::morpho::distanceMap2dImg (const ipsdk::image::ImageConstPtr &pInBinImg, const ipsdk::image::ImagePtr &pOutDistImg)
 wrapper function for distance map transform of an input binary image More...
 
IPSDKIPLBASICMORPHOLOGY_API ipsdk::image::ImagePtr ipsdk::imaproc::morpho::distanceMap2dImg (const ipsdk::image::ImageConstPtr &pInBinImg, const ipsdk::ipReal32 maxDistance)
 wrapper function for distance map transform of an input binary image constrained to a maximum distance propagation More...
 
IPSDKIPLBASICMORPHOLOGY_API void ipsdk::imaproc::morpho::distanceMap2dImg (const ipsdk::image::ImageConstPtr &pInBinImg, const ipsdk::ipReal32 maxDistance, const ipsdk::image::ImagePtr &pOutDistImg)
 wrapper function for distance map transform of an input binary image constrained to a maximum distance propagation More...
 

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

Attributes description

Attribute description for algorithm :

Name ToolTip Default Initializer
ipsdk::imaproc::attr::InBinImg [Input] binary image for processing operation X
ipsdk::imaproc::attr::InOptMaxDistance [Input Optional] Maximum distance authorized for the propagation (a value of 0 means no distance restriction) X
ipsdk::imaproc::attr::OutDistImg [Output] distance map image ipsdk::imaproc::duplicateInOut (_pOutDistImg, _pInBinImg, ipsdk::image::eImageBufferType::eIBT_UInt16)

Global Rule description

Global rule description for algorithm :
ipsdk::imaproc::matchSize (_pInBinImg,_pOutDistImg)

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

Associated library

IPSDKIPLBasicMorphology

Header file

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);
See also
DistanceMap2dImgLvl1
DistanceMap2dImgLvl2

Function Documentation

◆ distanceMap2dImg() [1/4]

IPSDKIPLBASICMORPHOLOGY_API ipsdk::image::ImagePtr ipsdk::imaproc::morpho::distanceMap2dImg ( const ipsdk::image::ImageConstPtr pInBinImg)

wrapper function for distance map transform of an input binary image

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ distanceMap2dImg() [2/4]

IPSDKIPLBASICMORPHOLOGY_API ipsdk::image::ImagePtr ipsdk::imaproc::morpho::distanceMap2dImg ( const ipsdk::image::ImageConstPtr pInBinImg,
const ipsdk::ipReal32  maxDistance 
)

wrapper function for distance map transform of an input binary image constrained to a maximum distance propagation

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ distanceMap2dImg() [3/4]

IPSDKIPLBASICMORPHOLOGY_API void ipsdk::imaproc::morpho::distanceMap2dImg ( const ipsdk::image::ImageConstPtr pInBinImg,
const ipsdk::image::ImagePtr pOutDistImg 
)

wrapper function for distance map transform of an input binary image

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ distanceMap2dImg() [4/4]

IPSDKIPLBASICMORPHOLOGY_API void ipsdk::imaproc::morpho::distanceMap2dImg ( const ipsdk::image::ImageConstPtr pInBinImg,
const ipsdk::ipReal32  maxDistance,
const ipsdk::image::ImagePtr pOutDistImg 
)

wrapper function for distance map transform of an input binary image constrained to a maximum distance propagation

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure