Rate This Document
Findability
Accuracy
Completeness
Readability

TrueDistanceTransform

Calculates the Euclidean distance from each non-zero pixel to the nearest zero pixel within the source image.

The function interface is declared as follows:

HmppResult HMPPI_TrueDistanceTransform_8u32f_C1R(const uint8_t* pSrc, int srcStep, float* pDst, int dstStep, HmppiSize roiSize);

Parameters

Parameter

Description

Value Range

Input/Output

pSrc

Pointer to the source vector

The value cannot be NULL.

Input

srcStep

Distance between starts of consecutive lines in the source image, in bytes

(0, INT_MAX]

Input

pDst

Pointer to the destination vector

The value cannot be NULL.

Output

dstStep

Distance between starts of consecutive lines in the destination image, in bytes

(0, INT_MAX]

Input

roiSize

Size of the ROI of the source and destination images, in pixels

roiSize.width ∈ (0, INT_MAX], roiSize.height ∈ (0, INT_MAX]

Input

Return Value

  • Success: HMPP_STS_NO_ERR
  • Failure: An error code is returned.

Error Codes

Error Code

Description

HMPP_STS_NULL_PTR_ERR

The value of pSrc, pDst, or pMetrics is NULL.

HMPP_STS_STEP_ERR

The value of srcStep is less than or equal to 0.

HMPP_STS_SIZE_ERR

The value of roiSize.width or roiSize.height is less than or equal to 0.

Example

#include <stdio.h>
#include "hmppi.h"
#include "hmpp_type.h"
void TrueDistanceTransformExample()
{
    HmppiSize roi = {5, 7};
    uint8_t src[45] = {1, 0, 3, 4, 5,
                       1, 2, 3, 4, 5,
                       1, 2, 3, 4, 5,
                       1, 2, 0, 4, 5,
                       1, 2, 3, 4, 5,
                       1, 2, 3, 4, 5,
                       1, 2, 3, 4, 5,
                       1, 2, 3, 4, 0,
                       1, 2, 3, 4, 5
                      };
    float dst[49] = {0};
    int32_t srcStep = 5 * sizeof(uint8_t);
    int32_t dstStep = 7 * sizeof(float);
    HmppResult res = HMPPI_TrueDistanceTransform_8u32f_C1R(src, srcStep, dst, dstStep, roi);
    printf("result: %d\n", (int)res);
    for (int i = 0; i < 7; i++) {
        for (int j = 0; j < 7; j++) {
            printf("%.2f ", dst[i * 7 + j]);
        }
        printf("\n");
    }
}
int main()
{
    TrueDistanceTransformExample();
    return 0;
}

Output:

result: 0
1.00 0.00 1.00 2.00 3.00 0.00 0.00 
1.41 1.00 1.41 2.24 2.83 0.00 0.00 
2.24 1.41 1.00 1.41 2.24 0.00 0.00 
2.00 1.00 0.00 1.00 2.00 0.00 0.00 
2.24 1.41 1.00 1.41 2.24 0.00 0.00 
2.83 2.24 2.00 2.24 2.83 0.00 0.00 
3.61 3.16 3.00 3.16 3.61 0.00 0.00