Rate This Document
Findability
Accuracy
Completeness
Readability

LabelMarkers

Assigns a numerical label to each connected component within an image.

The function interface is declared as follows:

  • In-place operation

    HmppResult HMPPI_LabelMarkers_8u_C1IR(uint8_t* pMarker, int markerStep, HmppiSize roiSize, int minLabel, int maxLabel, HmppiNorm norm, int* pNumber);

    HmppResult HMPPI_LabelMarkers_16u_C1IR(uint16_t* pMarker, int markerStep, HmppiSize roiSize, int minLabel, int maxLabel, HmppiNorm norm, int* pNumber);

  • Not-in-place operation

    HmppResult HMPPI_LabelMarkers_16u8u_C1R(uint16_t* pSrc, int srcMarkerStep, uint8_t* pMarker, int dstMarkerStep, HmppiSize roiSize, int minLabel, int maxLabel, HmppiNorm norm, int* pNumber);

Parameter

Description

Value Range

Input/Output

pMarker

Pointer to the ROI of the source and destination images (in-place operations)

The value cannot be NULL.

Input/Output

markerStep

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

The value must be zero or a positive integer.

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

minLabel

Minimum label value

minLabel∈[1, 255], minLabel <= maxLabel

Input

maxLabel

Maximum label value

maxLabel∈[1, 255], minLabel <= maxLabel

Input

pSrcMarker

Pointer to the source image ROI (non-in-place operation)

The value cannot be NULL.

Input

pMarker

Pointer to the destination image ROI (non-in-place operation)

The value cannot be NULL.

Output

srcMarkerStep

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

The value must be zero or a positive integer.

Input

dstMarkerStep

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

The value must be zero or a positive integer.

Input

norm

Norm flag, specifying whether 4-connectivity or 8-connectivity is utilized to calculate connected components.

HMPP_NORML1: 4-connectivity; HMPP_NORMINF: 8-connectivity

Input

pNumber

Pointer to the number of connected components

The value cannot be NULL.

Output

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 pMarker or pSrcMarker is NULL.

HMPP_STS_STEP_ERR

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

HMPP_STS_BAD_ARG_ERR

The value of minLabel or maxLabel is not within the range [1, 255], or minLabel is greater than maxLabel.

HMPP_STS_SIZE_ERR

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

HMPP_STS_MALLOC_FAILED

The auxiliary buffer fails to be allocated.

Example

#include <stdio.h>
#include "hmppi.h"
#include "hmpp_type.h"
void LabelMarkersExample()
{
    HmppiSize roi = {7, 6};
    uint8_t srcDst[50] = { 0, 0, 0, 0, 1, 1, 0,
                        0, 1, 1, 0, 1, 1, 0,
                        0, 1, 1, 0, 1, 1, 0,
                        0, 0, 0, 0, 1, 1, 0,
                        0, 0, 1, 0, 0, 0, 0,
                        0, 0, 0, 0, 0, 0, 1,
                      };
    int32_t srcDstStep = 7 * sizeof(uint8_t);
    HmppiPoint seed = {3, 3};
    uint8_t minLabel = 1;
    uint8_t maxLabel = 8;
    HmppiNorm norm = HMPP_NORML1;
    int number;
    HmppResult res = HMPPI_LabelMarkers_8u_C1IR(srcDst, srcDstStep, roi, minLabel, maxLabel,norm, &number);
    printf("result: %d\n", (int)res);
    for (int i = 0; i < 7; i++) {
        for (int j = 0; j < 7; j++) {
            printf("%d ", srcDst[i * 7 + j]);
        }
        printf("\n");
    }
}
int main()
{
    LabelMarkersExample();
    return 0;
}

Output:

result: 0
0 0 0 0 1 1 0 
0 2 2 0 1 1 0 
0 2 2 0 1 1 0 
0 0 0 0 1 1 0 
0 0 3 0 0 0 0 
0 0 0 0 0 0 4 
0 0 0 0 0 0 0