我要评分
获取效率
正确性
完整性
易理解

Dilate3x3

Function description:

Performs a dilation on an image using a 3 x 3 mask. This is a special case of DilateBorder, in which all mask values are non-zero valid by default.

A dilation is to obtain the maximum value of all pixels in the neighborhood. It is represented by and defined as follows:

The formula indicates that image A is dilated by mask B (3 x 3). This function convolves image A with mask B. It scans all pixels in the image, calculates the maximum pixel value in a region covered by mask B, and replaces the pixel value specified by the anchor point with this maximum value.

The following figure shows the interface input and output.

The function interface declaration is as follows:

HmppResult HMPPI_Dilate3x3_64f_C1R(const double *src, int32_t srcStep, double *dst, int32_t dstStep, HmppiSize roiSize);

Parameters

Parameter

Description

Value Range

Input/Output

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

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 is 0 or negative.

HMPP_STS_STEP_ERR

The value of srcStep or dstStep is 0 or negative.

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 of roiSize plus 2.

The width and height of the source or destination picture must be two pixels greater than those specified by roiSize. Otherwise, HMPP_STS_ROI_ERR is returned.

Example

#define SRC_BUFFER_SIZE_T 96
#define DST_BUFFER_SIZE_T 64
void Dilate3x3Example()
{
    HmppiSize roi = { 4, 4 };
    const double src[SRC_BUFFER_SIZE_T] = {
        11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66,
        11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66,
        11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66,
        11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66,
        11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66,
        11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66,
        11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66,
        11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66
    };

    double dst[DST_BUFFER_SIZE_T] = { 0 };

    const int32_t srcWidth = 12;
    const int32_t dstWidth = 8;
    int32_t srcStep = srcWidth * sizeof(double);
    int32_t dstStep = dstWidth * sizeof(double);
    HmppResult result = HMPPI_Dilate3x3_64f_C1R(src, srcStep, dst, dstStep, roi);

    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("%.2lf ", dst[i]);
    }
    printf("\n");
}


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

Output:

result = 0
dst =
66.00 33.00 44.00 55.00 0.00 0.00 0.00 0.00
66.00 33.00 44.00 55.00 0.00 0.00 0.00 0.00
66.00 33.00 44.00 55.00 0.00 0.00 0.00 0.00
66.00 33.00 44.00 55.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00