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

FilterLaplacianBorder

This function applies the Laplacian filter to the source image src and stores the result to the destination image dst. The border pixel value is obtained based on the border type and border value assignment parameters. The kernel for this filter is a 3x3 or 5x5 matrix mask specified by parameters. The kernel has the following values, with the anchor located in the center cell.

2 4 4 4 2

2 0 2 4 0 -8 0 4

0 -8 0 4 -8 -24 -8 4

2 0 2 4 0 -8 0 4

2 4 4 4 2

You need to use FilterLaplacianInit to apply for the buffer space required by this function and use the space in main functions.

The function interface declaration is as follows:

  • Functions for applying for and releasing auxiliary space buffers:

    HmppResult HMPPI_FilterLaplacianInit_8u16s_C1R(HmppiSize roiSize, HmppiMaskSize mask, uint8_t **buffer);

    HmppResult HMPPI_FilterLaplacianInit_32f_C1R(HmppiSize roiSize, HmppiMaskSize mask, uint8_t **buffer);

    HmppResult HMPPI_FilterLaplacianRelease(uint8_t *buffer);

  • Main functions:

    HmppResult HMPPI_FilterLaplacianBorder_8u16s_C1R(const uint8_t *src, int32_t srcStep, int16_t *dst, int32_t dstStep, HmppiSize roiSize, HmppiMaskSize maskSize, HmppiBorderType borderType, uint8_t borderValue, uint8_t *buffer);

    HmppResult HMPPI_FilterLaplacianBorder_32f_C1R(const float *src, int32_t srcStep, float *dst, int32_t dstStep,HmppiSize roiSize, HmppiMaskSize maskSize, HmppiBorderType borderType, float borderValue, uint8_t *buffer);

Parameters

Parameter

Description

Value Range

Input/Output

src

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

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

(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

maskSize

Predefined mask

HmppMskSize3x3 or HmppMskSize5x5

Input

borderType

Border type

The value is one of the following enumerated values of HmppiBorderType:

HMPPI_BORDER_CONST

HMPPI_BORDER_REPL

HMPPI_BORDER_MIRROR

Input

borderValue

Constant value of the constant border pixel. This parameter is valid only when borderType = HMPPI_BORDER_CONST is used.

Value within the data type range

Input

buffer

Pointer to the buffer required for calculation. Apply for and initialize space in init, release space in release, and use the applied space in main functions.

The value cannot be NULL.

Input/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 src or dst is NULL.

HMPP_STS_SIZE_ERR

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

HMPP_STS_STEP_ERR

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

HMPP_STS_ROI_ERR

roiSize.width x Number of bytes occupied by the data type > Step

HMPP_STS_NOT_EVEN_STEP_ERR

The value of srcStep or dstStep cannot be exactly divided by the byte length of the data type to which src or dst belongs.

HMPP_STS_BAD_ARG_ERR

The value of borderType or maskSize is not supported.

Example

#define SRC_BUFFER_SIZE_T 28
#define DST_BUFFER_SIZE_T 16

int LaplacianBorderExample()
{
    HmppiSize roi = { 2, 4 };
    const float src[SRC_BUFFER_SIZE_T] = { 9.8375815e-16, 4.5484828e-16, 1.4972698e-14, -1.3397389e+25, 1.9061152e+27, -8.8007769e+17, -217025.86, -6.2768196e+14, 4.4335606e+33, 1.0258707e-13, -9.3150633e-11, -5192.7163, 2.536292e+25, 6.0832354e+15, 8.5712402e+29, -0.15451884, -0.2848247, -2.1714717e+10, 2.7212473e+17, -1.3591454e-22, 7.6473188e+21, -2.2729285e-30, 1129877.1, -1.0089557e-05, -1.1054221e+21, -3.8945858e-19, -6.8345717e-34, 60685416};
    float dst[DST_BUFFER_SIZE_T] = {0};

    int32_t srcStep = 4 * sizeof(float);
    int32_t dstStep = 4 * sizeof(float);
    uint8_t *buffer = NULL;
    HmppResult result = HMPPI_FilterLaplacianInit_32f_C1R(roi, HmppMskSize3x3, &buffer);

    if (result == HMPP_STS_NO_ERR) {
        result = HMPPI_FilterLaplacianBorder_32f_C1R(src, srcStep, dst, dstStep, roi, HmppMskSize3x3, HMPPI_BORDER_MIRROR, 0.0f, buffer);
    }
    if (result != HMPP_STS_NO_ERR) {
        printf("result error: %d\n", result);
    }
    printf("dst= ");
    for(int32_t i = 0; i < DST_BUFFER_SIZE_T; i++){
        printf("%f ",dst[i]);
    }
    printf("\n");
    HMPPI_FilterLaplacianRelease(buffer);
    buffer = NULL;
    return 0;
}

Output:

result = 0
dst = -7.0406216e+18 1.5248922e+28 -3.9418209e+28 7.7666443e+28 -1.5248922e+28 1.7734242e+34 5.1225988e+27 -2.04904e+27 -3.5468485e+34 7.7259126e+27 -2.2689171e+31 2.2694294e+31 -2.0290336e+26 3.5468485e+34 0 0