DistanceTransform

Calculates distance to the closest zero pixel for all non-zero pixels of source image.

Syntax

Case 1: Not-in-place operations

IppStatus ippiDistanceTransform_3x3_<mod>(const Ipp8u* pSrc, int srcStep, Ipp<dstDatatype>* pDst, int dstStep, IppiSize roiSize, Ipp32s* pMetrics);

IppStatus ippiDistanceTransform_5x5_<mod>(const Ipp8u* pSrc, int srcStep, Ipp<dstDatatype>* pDst, int dstStep, IppiSize roiSize, Ipp32s* pMetrics);

Supported values for mod:

8u_C1R

8u16u_C1R

IppStatus ippiDistanceTransform_3x3_8u32f_C1R(const Ipp8u* pSrc, int srcStep, Ipp32f* pDst, int dstStep, IppiSize roiSize, Ipp32f* pMetrics);

IppStatus ippiDistanceTransform_5x5_8u32f_C1R(const Ipp8u* pSrc, int srcStep, Ipp32f* pDst, int dstStep, IppiSize roiSize, Ipp32f* pMetrics);

Case 2: In-place operations

IppStatus ippiDistanceTransform_3x3_8u_C1IR(Ipp8u* pSrcDst, int srcDstStep, IppiSize roiSize, Ipp32s* pMetrics);

IppStatus ippiDistanceTransform_5x5_8u_C1IR(Ipp8u* pSrcDst, int srcDstStep, IppiSize roiSize, Ipp32s* pMetrics);

Parameters

pSrc
Pointer to the source image ROI.
srcStep
Distance in bytes between starts of consecutive lines in the source image.
pDst
Pointer to the ROI in the destination distance image.
dstStep
Distance in bytes between starts of consecutive lines in the destination image.
pSrcDst
Pointer to the source and destination image ROI for in-place operation.
srcDstStep
Distance in bytes between starts of consecutive lines in the source and destination image for in-place operation.
roiSize
Size of the image ROI in pixels.
pMetrics
Pointer to the array that specifies used metrics.

Description

The distance transform function ippiDistanceTransform is declared in the ippcv.h file. It operates with ROI (see Regions of Interest in Intel IPP).

This function approximates the actual distance from the closest zero pixel to each certain pixel with the sum of atomic distances from the fixed set. The set consists of two values for a 3x3 mask and three values for a 5x5 mask.

Figure “3x3 Mask” shows the result of the distance transform of a 7x7 image with zero point in the center. This example corresponds to a 3x3 mask. Two numbers specify metrics in case of the 3x3 mask:

In this case the values are 1 and 1.5 correspondingly.

3x3 Mask
4.5 4 3.5 3 3.5 4 4.5
4 3 2.5 2 2.5 3 4
3.5 2.5 1.5 1 1.5 2.5 3.5
3 2 1 0 1 2 3
3.5 2.5 1.5 1 1.5 2.5 3.5
4 3 2.5 2 2.5 3 4
4.5 4 3.5 3 3.5 4 4.5

Figure “5x5 Mask” shows the distance transform for the same image, but for a 5x5 mask.

For this mask yet another number is added to specify metrics - the additional distance, i.e., the distance between pixels corresponding to the chess knight move.

In this example, the additional distance is equal to 2.

5x5 Mask 
4 3.5 3 3 3 3.5 4
3.5 3 2 2 2 3 3.5
3 2 1.5 1 1.5 2 3
3 2 1 0 1 2 3
3 2 1.5 1 1.5 2 3
3.5 3 2 2 2 3 3.5
4 3.5 3 3 3 3.5 4

Example “Using the function ippiDistanceTransform_3x3” shows how to use the function ippiDistanceTransform_3x3_8u_C1R.

Return Values

ippStsNoErr

Indicates no error. Any other value indicates an error or a warning.

ippStsNullPtrErr

Indicates an error condition if one of the specified pointers is NULL.

ippStsSizeErr

Indicates an error condition if roiSize has a field with zero or negative value.

ippStsStepErr

Indicates an error condition if srcStep or dstStep is less than roiSize.width*<pixelSize>.

ippStsNotEvenStepErr

Indicates an error condition if step value is not divisible by 2 for 16u images, and by 4 for 32f images.

ippStsCoeffErr

Indicates an error condition if at least one element of pMetrics array has zero or negative value.

Using the function ippiDistanceTransform_3x3

Ipp8u
src[7*7] = {
     1, 2, 3, 4, 5, 6, 7,
     1, 0, 3, 4, 5, 6, 7,
     1, 2, 3, 4, 5, 6, 7,
     1, 2, 3, 0, 5, 6, 7,
     1, 2, 3, 4, 5, 6, 7,
     1, 2, 3, 4, 5, 0, 7,
     1, 2, 3, 4, 5, 6, 7
    };
Ipp8u dst[7*7];
IppiSize roiSize = { 7, 7 };
Ipp32s pMetrics[2] = { 2, 2 };
 
ippiDistanceTransform_3x3_8u_C1R ( src, 7, dst, 7, roiSize, pMetrics );
result:
1 2 3 4 5 6 7
1 0 3 4 5 6 7
1 2 3 4 5 6 7
1 2 3 0 5 6 7    src
1 2 3 4 5 6 7
1 2 3 4 5 0 7
1 2 3 4 5 6 7
 
2 2 2 4 6 6 6
2 0 2 4 4 4 6
2 2 2 2 2 4 6
4 4 2 0 2 4 4    dst
6 4 2 2 2 2 2
6 4 4 4 2 0 2
6 6 6 4 2 2 2




Submit feedback on this help topic

Copyright © 2000 - 2011, Intel Corporation. All rights reserved.