Rate This Document
Findability
Accuracy
Completeness
Readability

MorphOpenBorder

Opens an image using a mask. All mask values are non-zero valid by default. It is represented by and defined as follows:

The formula represents that image A is opened by using mask B. The opening operation in morphology is in essence the dilation of the erosion of image A.

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 HmppiMorphAdvPolicy structure. Otherwise, the main function cannot be called successfully.
  2. Call the main function.
  3. Call Release to release the memory contained in the HmppiMorphAdvPolicy function. Otherwise, memory leak occurs.

The function interface declaration is as follows:

  • Initialization:

    HmppResult HMPPI_MorphAdvInit_1u_C1R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphAdvPolicy **policy);

    HmppResult HMPPI_MorphAdvInit_8u_C1R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphAdvPolicy **policy);

    HmppResult HMPPI_MorphAdvInit_16u_C1R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphAdvPolicy **policy);

    HmppResult HMPPI_MorphAdvInit_16s_C1R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphAdvPolicy **policy);

    HmppResult HMPPI_MorphAdvInit_32f_C1R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphAdvPolicy **policy);

    HmppResult HMPPI_MorphAdvInit_8u_C3R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphAdvPolicy **policy);

    HmppResult HMPPI_MorphAdvInit_32f_C3R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphAdvPolicy **policy);

    HmppResult HMPPI_MorphAdvInit_8u_C4R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphAdvPolicy **policy);

    HmppResult HMPPI_MorphAdvInit_32f_C4R(HmppiSize roiSize, const uint8_t *mask, HmppiSize maskSize, HmppiMorphAdvPolicy **policy);

  • Main functions:

    HmppResult HMPPI_MorphOpenBorder_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 HmppiMorphAdvPolicy *policy);

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

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

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

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

    HmppResult HMPPI_MorphOpenBorder_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 HmppiMorphAdvPolicy *policy);

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

    HmppResult HMPPI_MorphOpenBorder_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 HmppiMorphAdvPolicy *policy);

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

  • Memory release:

    HmppResult HMPPI_MorphAdvRelease_1u_C1R(HmppiMorphAdvPolicy *policy);

    HmppResult HMPPI_MorphAdvRelease_8u_C1R(HmppiMorphAdvPolicy *policy);

    HmppResult HMPPI_MorphAdvRelease_16u_C1R(HmppiMorphAdvPolicy *policy);

    HmppResult HMPPI_MorphAdvRelease_16s_C1R(HmppiMorphAdvPolicy *policy);

    HmppResult HMPPI_MorphAdvRelease_32f_C1R(HmppiMorphAdvPolicy *policy);

    HmppResult HMPPI_MorphAdvRelease_8u_C3R(HmppiMorphAdvPolicy *policy);

    HmppResult HMPPI_MorphAdvRelease_32f_C3R(HmppiMorphAdvPolicy *policy);

    HmppResult HMPPI_MorphAdvRelease_8u_C4R(HmppiMorphAdvPolicy *policy);

    HmppResult HMPPI_MorphAdvRelease_32f_C4R(HmppiMorphAdvPolicy *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

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

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

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.

Enumeration.

HMPP_BORDER_DEFAULT: Uses the HMPP_BORDER_CONST border type. The borderValue is set according to the selected basic operation (dilation or erosion).

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 memory that stores the pointer to HmppiMorphAdvPolicy

The value cannot be NULL.

Output

policy (in the main and release functions)

Pointer to the HmppiMorphAdvPolicy 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_STEP_ERR

The value of srcStep or dstStep is 0 or negative.

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 MorphOpenBorderExample()
{
    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;
    HmppiMorphAdvPolicy *policy = NULL;
    HmppResult result;

    result = HMPPI_MorphAdvInit_16s_C1R(roiSize, mask, maskSize, &policy);
    printf("HMPPI_MorphAdvInit_16s_C1R result = %d\n", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }
    result = HMPPI_MorphOpenBorder_16s_C1R(src, srcStep, dst, dstStep, roiSize, borderType, borderValue, policy);
    printf("HMPPI_MorphOpenBorder_16s_C1R result = %d\n", result);
    (void)HMPPI_MorphAdvRelease_16s_C1R(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)
{
    MorphOpenBorderExample();
    return 0;
}

Output:

HMPPI_MorphAdvInit_16s_C1R result = 0
HMPPI_MorphOpenBorder_16s_C1R result = 0
result = 0
dst =
 11  12  13  13   0   0   0   0
 21  22  23  23   0   0   0   0
 31  32  33  33   0   0   0   0
 31  32  33  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