IPSDK 4.1.0.2
IPSDK : Image Processing Software Development Kit
Generic Seeded Distance Map 2d
imagegenericSeededDistanceMap2dImg (inBinImg,inBinSeedImg,inDistWeight2d)
imagegenericSeededDistanceMap2dImg (inBinImg,inBinSeedImg,inDistWeight2d,maxDistance)

Detailed Description

generic seeded distance map transform of an input binary image according to a seeded image

2d generic seeded distance map algorithm allows to compute the distance to the closest seeded pixel in a region for each pixel of this region, according to given weights stored in a ipsdk::imaproc::attr::DistWeight2d attribute. As in Seeded Distance Map 2d, the region is defined by a binary image with pixel intensities set to 1 and the seeded pixels are defined by a seeded image with pixel intensities set to 1.The weights can be seen as a distance between 2 successive pixels. If the parameter $ maxDistance $ is provided, the propagation is constrained so that it stops when the distance is higher than the $ maxDistance $ value.

The resulting image buffer type must be one of the following :

Output image values are given by :

\[ OutDistImg[x, y] = \left\{ \begin{array}{rl} 0 &\mbox{\text{if } InBinImg[x, y] = 0} \\ 1 &\mbox{\text{if } InBinImg[x, y] \text{is a seeded pixel}} \\ \min\limits_{(x_d, y_d) \in \aleph \wedge InBinImg[x_d, y_d] > 0} {\left( InBinImg[x_d, y_d]+\omega_d \right) } &\mbox{otherwise} \end{array} \right. \]

Where $\aleph$ is the pixel's neighbourhood, $d$ is the set of directions allowed by $\aleph$ and can be lateral (along the x-axis), axial (along the y-axis) or diagonal. $\omega_d$ is the weight corresponding to the direction $d$.

Note
Weights with zero value are not taken into account.

The following figure illustrates the algorithm with a simple example :

genericSeededDistanceMap2dImg_example.png

If, for instance, $\omega_x = 1$, $\omega_y = 1$ and $\omega_{xy} = 0$. The neighbours along the diagonals are not taken into account : it corresponds to a 4-connexity. In this case, the resulting distance will be :

\begin{eqnarray*} OutDistImg[x, y] & = & \min \left( { \left\{ 127 + \omega_y, 127 + \omega_x, 129 + \omega_y \right\} } \right) \\ &=& \min \left( { \left( \left\{ 127 + 1, 127 + 1, 129 + 1 \right\} \right) } \right) \\ &=& 128 \end{eqnarray*}

Here is an example of a 2d generic seeded distance map computation applied to a binary input image with a real result image and with weighting coefficients along the x an y directions set to 1 and the weighting coefficient along the diagonal set to $ \sqrt{2} $ :

genericSeededDistanceMap2dImg.png

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLAdvancedMorphology as advmorpho

Code Example

# opening of input images
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
inSeedsImg = PyIPSDK.loadTiffImageFile(inputSeedsImgPath)
# setting of used distance weights
inDistWeight2d = PyIPSDK.createDistWeight2d(3, 4, 5)
# generic seeded distance map 2d computation
outDistImg = advmorpho.genericSeededDistanceMap2dImg(inImg, inSeedsImg, inDistWeight2d)

Example of C++ code :

Example informations

Header file

#include <IPSDKIPL/IPSDKIPLAdvancedMorphology/Processor/GenericSeededDistanceMap2dImg/GenericSeededDistanceMap2dImg.h>

Code Example

// opening input image
ImagePtr pInBinImg = loadTiffImageFile(inputImgPath);
// opening seed input image
ImagePtr pInSeedImg = loadTiffImageFile(inputSeedImgPath);
// Distance weighting coefficients
DistWeight2dPtr pDistWeight2d = createDistWeight2d(xWeight, yWeight, xyWeight);
// define output image geometry
ImageGeometryPtr pDistGeometry = geometry2d(outputImageBufferType,
pInBinImg->getSizeX(),
pInBinImg->getSizeY());
// creation of output image
boost::shared_ptr<MemoryImage> pOutDistImg(boost::make_shared<MemoryImage>());
pOutDistImg->init(*pDistGeometry);
// compute distance map on input image
genericSeededDistanceMap2dImg(pInBinImg, pInSeedImg, pDistWeight2d, pOutDistImg);