Rate This Document
Findability
Accuracy
Completeness
Readability

Threshold

Performs thresholding on pixels in an image. This function changes pixel values based on a specified value. The type of comparison operation for thresholding is specified by the HMPPCmpOp parameter. Comparison for either "greater than" or "less than" can be used. If the comparison condition is met, the corresponding output pixel is set to the specified threshold value. Otherwise, the output pixel value is not changed or set. The calculation formula is as follows:

  • If cmpOp is set to HMPP_CMPLESS, if the pixel value in src is less than the threshold, the threshold value is assigned to dst; otherwise, the pixel value in src is assigned to dst.

  • If cmpOp is set to HMPP_CMPGREATER, if the pixel value in src is greater than the threshold, the threshold value is assigned to dst; otherwise, the pixel value in src is assigned to dst.

The function interface declaration is as follows:

  • Thresholding for single-channel data:

    HmppResult HMPPI_Threshold_8u_C1R(const uint8_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, uint8_t threshold, HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_16u_C1R(const uint16_t *src, int32_t srcStep, uint16_t *dst, int32_t dstStep, HmppiSize roiSize, uint16_t threshold, HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_16s_C1R(const int16_t *src, int32_t srcStep, int16_t *dst, int32_t dstStep, HmppiSize roiSize, int16_t threshold, HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_32f_C1R(const float *src, int32_t srcStep, float *dst, int32_t dstStep, HmppiSize roiSize, float threshold, HmppCmpOp cmpOp);

  • Thresholding for multi-channel data:

    HmppResult HMPPI_Threshold_8u_C3R(const uint8_t *src, int32_t srcStep, uint8_t*dst, int32_t dstStep, HmppiSize roiSize, const uint8_t threshold[3], HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_16u_C3R(const uint16_t *src, int32_t srcStep, uint16_t*dst, int32_t dstStep, HmppiSize roiSize, const uint16_t threshold[3], HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_16s_C3R(const int16_t *src, int32_t srcStep, int16_t*dst, int32_t dstStep, HmppiSize roiSize, const int16_t threshold[3], HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_32f_C3R(const float *src, int32_t srcStep, float*dst, int32_t dstStep, HmppiSize roiSize, const float threshold[3], HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_8u_AC4R(const uint8_t *src, int32_t srcStep, uint8_t*dst, int32_t dstStep, HmppiSize roiSize, const uint8_t threshold[3], HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_16u_AC4R(const uint16_t *src, int32_t srcStep, uint16_t*dst, int32_t dstStep, HmppiSize roiSize, const uint16_t threshold[3], HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_16s_AC4R(const int16_t *src, int32_t srcStep, int16_t*dst, int32_t dstStep, HmppiSizeroiSize, const int16_t threshold[3], HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_32f_AC4R(const float *src, int32_t srcStep, float*dst, int32_t dstStep, HmppiSizeroiSize, const float threshold[3], HmppCmpOp cmpOp);

  • In-place thresholding for single-channel data:

    HmppResult HMPPI_Threshold_8u_C1IR(uint8_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, uint8_t threshold, HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_16u_C1IR(uint16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, uint16_t threshold, HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_16s_C1IR(int16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, int16_t threshold, HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_32f_C1IR(float *srcDst, int32_t srcDstStep, HmppiSize roiSize, float threshold, HmppCmpOp cmpOp);

  • In-place thresholding for multi-channel data:

    HmppResult HMPPI_Threshold_8u_C3IR(uint8_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, const uint8_t threshold[3], HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_16u_C3IR(uint16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, const uint16_t threshold[3], HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_16s_C3IR(int16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, const int16_t threshold[3], HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_32f_C3IR(float *srcDst, int32_t srcDstStep, HmppiSize roiSize, const float threshold[3], HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_8u_AC4IR(uint8_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, const uint8_t threshold[3], HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_16u_AC4IR(uint16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, const uint16_t threshold[3], HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_16s_AC4IR(int16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, const int16_t threshold[3], HmppCmpOp cmpOp);

    HmppResult HMPPI_Threshold_32f_AC4IR(float *srcDst, int32_t srcDstStep, HmppiSize roiSize, const float threshold[3], HmppCmpOp cmpOp);

Parameters

Parameter

Description

Value Range

Input/Output

src

Pointer to the source image ROI

The value cannot be NULL.

Input

srcStep

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

The value must be zero or a positive integer.

Input

dst

Pointer to the destination image ROI

The value cannot be NULL.

Output

dstStep

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

The value must be zero or a positive integer.

Input

srcDst

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

The value cannot be NULL.

Input/Output

srcDstStep

Distance between starts of consecutive lines in the source and destination image (in-place operations), 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

threshold

Threshold value used by each pixel. In the case of multi-channel data, an array of threshold values for each color channel is used.

Any value

Input

cmpOp

Operation used to compare pixel values and the threshold Comparison for "greater than" or "less than" can be used.

HMPP_CMP_LT, HMPP_CMP_GT

Input

Return Value

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

Error Codes

Error Code

Description

HMPP_STS_NO_ERR

The output is normal.

HMPP_STS_NULL_PTR_ERR

The value of src, dst, or srcDst is NULL.

HMPP_STS_SIZE_ERR

The width or height of roiSize is zero or negative.

HMPP_STS_STEP_ERR

The value of srcStep, dstStep, or srcDstStep is zero or negative.

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_ROI_ERR

roiSize.width > Step

HMPP_STS_NOT_SUPPORTED_MODE_ERR

The comparison mode is not supported.

Example

void ThresholdExample()
{
    HmppiSize roi = {3,4};
    uint8_t src[9*4] = { 1, 2, 4, 8, 16, 8, 4, 2, 1, 
                   1, 2, 4, 8, 16, 8, 4, 2, 1, 
                   1, 2, 4, 8, 16, 8, 4, 2, 1, 
                   1, 2, 4, 8, 16, 8, 4, 2, 1};
    uint8_t dst[9*4] = {0};
    uint8_t threshold[3] = {8,8,8};
    int srcStep=9*sizeof(uint8_t);
    int dstStep=9*sizeof(uint8_t);

    HMPPI_Threshold_8u_C3R(src, srcStep, dst, dstStep, roi, threshold, HMPP_CMP_LT);
    for (int i = 0; i < 4; i++){
        for (int j = 0; j < 9; j++){
            printf("%4d ",dst[i*9+j]);
        }
        printf("\n");
    }
}

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

Output:

   8    8    8    8   16    8    8    8    8
   8    8    8    8   16    8    8    8    8
   8    8    8    8   16    8    8    8    8
   8    8    8    8   16    8    8    8    8