Rate This Document
Findability
Accuracy
Completeness
Readability

ErodeBorder

Performs an erosion on an image using a mask.

The minimum value is calculated only for non-zero elements in the mask image.

The following figure shows the interface input and output.

For details about the border types supported by this function, see the description about HmppiBorderType in Enumeration Types.

Mixed borders are also supported. For example, HMPP_BORDERREPL | HMPP_BORDERINMEM_TOP indicates that the top border is made by using HMPP_BORDERINMEM and the rest of the borders are made by using HMPP_BORDERREPL.

The function is called as follows:

  1. Call the Init function to initialize the HmppiMorphPolicy structure. Otherwise, the main function cannot be called successfully.
  2. Call the main function.
  3. Call Release to release the memory contained in the HmppiMorphPolicy function. Otherwise, memory leak occurs.

The function interface is declared as follows:

  • Initialization:

    HmppResult HMPPI_MorphInit(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppDataType dataType, int32_t numChannels, HmppiMorphPolicy **policy);

    HmppResult HMPPI_ErodeInit(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppDataType dataType, int32_t numChannels, HmppiMorphPolicy **policy);

    HmppResult HMPPI_MorphologyBorderInit_1u_C1R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphPolicy **policy);

    HmppResult HMPPI_MorphologyBorderInit_8u_C1R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphPolicy **policy);

    HmppResult HMPPI_MorphologyBorderInit_16u_C1R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphPolicy **policy);

    HmppResult HMPPI_MorphologyBorderInit_16s_C1R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphPolicy **policy);

    HmppResult HMPPI_MorphologyBorderInit_32f_C1R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphPolicy **policy);

    HmppResult HMPPI_MorphologyBorderInit_8u_C3R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphPolicy **policy);

    HmppResult HMPPI_MorphologyBorderInit_32f_C3R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphPolicy **policy);

    HmppResult HMPPI_MorphologyBorderInit_8u_C4R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphPolicy **policy);

    HmppResult HMPPI_MorphologyBorderInit_32f_C4R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphPolicy **policy);

  • Main functions:

    HmppResult HMPPI_ErodeBorder_1u_C1R(const uint8_t *src, int32_t srcStep, int32_t srcBitOffset, uint8_t *dst, int32_t dstStep, int32_t dstBitOffset, HmppiSize roiSize, HmppiBorderType borderType, uint8_t borderValue, const HmppiMorphPolicy *policy);

    HmppResult HMPPI_ErodeBorder_8u_C1R(const uint8_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, HmppiBorderType borderType, uint8_t borderValue, const HmppiMorphPolicy *policy);

    HmppResult HMPPI_ErodeBorder_16u_C1R(const uint16_t *src, int32_t srcStep, uint16_t *dst, int32_t dstStep, HmppiSize roiSize, HmppiBorderType borderType, uint16_t borderValue, const HmppiMorphPolicy *policy);

    HmppResult HMPPI_ErodeBorder_16s_C1R(const int16_t *src, int32_t srcStep, int16_t *dst, int32_t dstStep, HmppiSize roiSize, HmppiBorderType borderType, int16_t borderValue, const HmppiMorphPolicy *policy);

    HmppResult HMPPI_ErodeBorder_32f_C1R(const float *src, int32_t srcStep, float *dst, int32_t dstStep, HmppiSize roiSize, HmppiBorderType borderType, float borderValue, const HmppiMorphPolicy *policy);

    HmppResult HMPPI_ErodeBorder_8u_C3R(const uint8_t* src, int32_t srcStep, uint8_t* dst, int32_t dstStep, HmppiSize roiSize, HmppiBorderType borderType, const uint8_t borderValue[3], const HmppiMorphPolicy* policy);

    HmppResult HMPPI_ErodeBorder_32f_C3R(const float *src, int32_t srcStep, float *dst, int32_t dstStep, HmppiSize roiSize, HmppiBorderType borderType, const float borderValue[3], const HmppiMorphPolicy *policy);

    HmppResult HMPPI_ErodeBorder_8u_C4R(const uint8_t* src, int32_t srcStep, uint8_t* dst, int32_t dstStep, HmppiSize roiSize, HmppiBorderType borderType, const uint8_t borderValue[4], const HmppiMorphPolicy* policy);

    HmppResult HMPPI_ErodeBorder_32f_C4R(const float *src, int32_t srcStep, float *dst, int32_t dstStep, HmppiSize roiSize, HmppiBorderType borderType, const float borderValue[4], const HmppiMorphPolicy *policy);

  • Memory release:

    HmppResult HMPPI_MorphRelease(HmppiMorphPolicy *policy);

    HmppResult HMPPI_ErodeRelease(HmppiMorphPolicy *policy);

    HmppResult HMPPI_MorphologyBorderRelease_1u_C1R(HmppiMorphPolicy *policy);

    HmppResult HMPPI_MorphologyBorderRelease_8u_C1R(HmppiMorphPolicy *policy);

    HmppResult HMPPI_MorphologyBorderRelease_16u_C1R(HmppiMorphPolicy *policy);

    HmppResult HMPPI_MorphologyBorderRelease_16s_C1R(HmppiMorphPolicy *policy);

    HmppResult HMPPI_MorphologyBorderRelease_32f_C1R(HmppiMorphPolicy *policy);

    HmppResult HMPPI_MorphologyBorderRelease_8u_C3R(HmppiMorphPolicy *policy);

    HmppResult HMPPI_MorphologyBorderRelease_32f_C3R(HmppiMorphPolicy *policy);

    HmppResult HMPPI_MorphologyBorderRelease_8u_C4R(HmppiMorphPolicy *policy);

    HmppResult HMPPI_MorphologyBorderRelease_32f_C4R(HmppiMorphPolicy *policy);

Parameters

Parameter

Description

Value Range

Input/Output

mask

Pointer to the mask

The value cannot be NULL.

Input

maskSize

Size of the mask image, in pixels

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

Input

dataType

Data type of the source image (which is the same as that of the destination image)

Enumeration. Possible values are HMPP8U, HMPP16U, HMPP16S, and HMPP32F.

Input

numChannels

Number of channels for the source image (which is the same as that for the destination image)

Only 1, 3, and 4 channels are supported.

Input

src

Pointer to the source image

The value cannot be NULL.

Input

srcStep

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

The value must be a non-negative integer multiple of the bytes of src's data type.

Input

srcBitOffset

Offset from the first byte of the source image, in bits

(0, INT_MAX]. The sum of this parameter value and roiSize.width must be greater than or equal to srcStep x 8.

Input

dst

Pointer to the destination vector

The value cannot be NULL.

Output

dstStep

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

The value must be a non-negative integer multiple of the bytes of dst's data type.

Input

dstBitOffset

Offset from the first byte of the destination image, in bits

(0, INT_MAX]. The sum of this parameter value and roiSize.width must be greater than or equal to dstStep x 8.

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

borderType

Border type for border making (defined in the HmppiBorderType enumeration type)

The value is an element of HmppiBorderType:

  • HMPP_BORDER_DEFAULT: Uses the HMPP_BORDER_CONST border type, with borderValue set to MAX_VALUE.
  • HMPP_BORDER_REPL: The values for border pixels are copied from the boundary pixels of the source image.
  • HMPP_BORDER_IN_MEM: The values for border pixels are obtained from the source image pixels in memory.
  • HMPP_BORDER_CONST: The values for border pixels are set to a specified constant value.
  • HMPP_BORDER_MIRROR: The values for border pixels are mirrored from the boundary pixels of the source image.

Mixed borders are also supported.

Input

borderValue

Constant value that is assigned to pixels of the constant border (for the HMPP_BORDER_CONST border type)

Value within the data type range

Input

policy

(in the Init function)

Pointer to the pointer to the HmppiMorphPolicy structure

The value cannot be NULL.

Output

policy (in the main and release functions)

Pointer to the HmppiMorphPolicy structure

The value cannot be NULL.

Input

Return Value

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

Error Codes

Error Code

Description

HMPP_STS_NULL_PTR_ERR

Any of the specified pointers is NULL.

HMPP_STS_SIZE_ERR

The value of roiSize or maskSize is 0 or negative.

HMPP_STS_NOT_SUPPORTED_MODE_ERR

The specified data type is not supported for initialization.

HMPP_STS_NUMCHANNELS_ERR

The specified number of channels is not supported for initialization.

HMPP_STS_STEP_ERR

The value of srcStep, dstStep, srcBitOffset, or dstBitOffset is 0 or negative.

Or, the value of srcBitOffset or dstBitOffset does not meet the requirements of the roiSize field.

HMPP_STS_MALLOC_FAILED

The Init function failed to allocate the memory required by the algorithm model.

HMPP_STS_NOT_EVEN_STEP_ERR

The value of srcStep or dstStep is not an integer multiple of the bytes of the involved image's data type.

HMPP_STS_ROI_ERR

The width and height of the source or destination image are smaller than those specified by roiSize.

HMPP_STS_BORDER_ERR

The border type is not supported.

  • src and dst cannot be the same array or have overlapping memories. Otherwise, the result may be incorrect.
  • If the HMPP_BORDER_IN_MEM border type is used, ensure that the input source image has sufficient extra data for computation and that the minimum offset from the first byte of the source image is used when calling the main function. Otherwise, the system may crash. The offset must meet the following formula:

    T indicates the data type of the source image.

  • The 1u_C1R interface does not support HMPP_BORDER_MIRROR. If the border type is set to HMPP_BORDER_MIRROR, the HMPP_STS_BORDER_ERR error is returned.

Example

#define SRC_BUFFER_SIZE_T 96
#define DST_BUFFER_SIZE_T 64
#define MASK_BUFFER_SIZE_T 12
void ErodeBorderExample()
{
    HmppiSize roiSize = { 4, 4 };
    const int16_t src[SRC_BUFFER_SIZE_T] = {
        11, 12, 13, 14, 15, 16, 17, 18, 12, 19, 13, 15,
        21, 22, 23, 24, 25, 26, 27, 28, 22, 29, 23, 25,
        31, 32, 33, 34, 35, 36, 37, 38, 32, 39, 33, 35,
        41, 42, 43, 44, 45, 46, 47, 48, 42, 49, 43, 45,
        51, 52, 53, 54, 55, 56, 57, 58, 52, 59, 53, 55,
        61, 62, 63, 64, 65, 66, 67, 68, 62, 69, 63, 65,
        71, 72, 73, 74, 75, 76, 77, 78, 72, 79, 73, 75,
        81, 82, 83, 84, 85, 86, 87, 88, 82, 89, 83, 85
    };

    int16_t dst[DST_BUFFER_SIZE_T] = { 0 };
    HmppiSize maskSize = { 4, 3 };
    uint8_t mask[MASK_BUFFER_SIZE_T] = {
        1, 0, 2, 3,
        5, 1, 1, 0,
        0, 2, 0, 6,
    };

    const int32_t srcWidth = 12;
    const int32_t dstWidth = 8;
    int32_t srcStep = srcWidth * sizeof(int16_t);
    int32_t dstStep = dstWidth * sizeof(int16_t);
    HmppDataType dataType = HMPP16S;
    int32_t numChannels = 1;
    HmppiBorderType borderType = HMPPI_BORDER_REPL;
    int16_t borderValue = -100;
    HmppiMorphPolicy *policy = NULL;
    HmppResult result;

    result = HMPPI_MorphologyBorderInit_16s_C1R(roiSize, mask, maskSize, &policy);
    printf("HMPPI_MorphologyBorderInit_16s_C1R result = %d\n", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }
    result = HMPPI_ErodeBorder_16s_C1R(src, srcStep, dst, dstStep, roiSize, borderType, borderValue, policy);
    printf("HMPPI_ErodeBorder_16s_C1R result = %d\n", result);
    (void)HMPPI_ErodeRelease(policy);
    policy = NULL;
    if (result != HMPP_STS_NO_ERR) {
        return;
    }

    printf("result = %d \ndst = ", result);
    if (result != HMPP_STS_NO_ERR) {
        printf("result error: %d\n", result);
    }

    for (int32_t i = 0; i < DST_BUFFER_SIZE_T; ++i) {
        if (i % dstWidth == 0) {
            printf("\n");
        }
        printf("%3d ", dst[i]);
    }
    printf("\n");
}

int main(void)
{
    ErodeBorderExample();
    return 0;
}

Output:

HMPPI_MorphologyBorderInit_16s_C1R result = 0
HMPPI_ErodeBorder_16s_C1R result = 0
result = 0
dst =
 11  11  12  13   0   0   0   0
 11  11  12  13   0   0   0   0
 21  21  22  23   0   0   0   0
 31  31  32  33   0   0   0   0
  0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0
  0   0   0   0   0   0   0   0