Threshold_Val
Performs thresholding on pixels in an image. This function changes pixel values based on the threshold 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 value of value. Otherwise, the output pixel value is not changed or set. For images with multi-channel data, you need to set comparison conditions for each channel. The calculation formulas are as follows:
- If cmpOp is set to HMPP_CMPLESS and the pixel value in src is less than the threshold, the value of value is assigned to dst; otherwise, the pixel value in src is assigned to dst.

- If cmpOp is set to HMPP_CMPGREATER and the pixel value in src is greater than the threshold, the value of 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_Val_8u_C1R(const uint8_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, uint8_t threshold, uint8_t value, HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_16u_C1R(const uint16_t *src, int32_t srcStep, uint16_t *dst, int32_t dstStep, HmppiSize roiSize, uint16_t threshold, uint16_t value, HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_16s_C1R(const int16_t *src, int32_t srcStep, int16_t *dst, int32_t dstStep, HmppiSize roiSize, int16_t threshold, int16_t value, HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_32f_C1R(const float *src, int32_t srcStep, float *dst, int32_t dstStep, HmppiSize roiSize, float threshold, float value, HmppCmpOp cmpOp);
- Thresholding for multi-channel data:
HmppResult HMPPI_Threshold_Val_8u_C3R(const uint8_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, const uint8_t threshold[3], const uint8_t value[3], HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_16u_C3R(const uint16_t *src, int32_t srcStep, uint16_t *dst, int32_t dstStep, HmppiSize roiSize, const uint16_t threshold[3], const uint16_t value[3], HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_16s_C3R(const int16_t *src, int32_t srcStep, int16_t *dst, int32_t dstStep, HmppiSize roiSize, const int16_t threshold[3], const int16_t value[3], HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_32f_C3R(const float *src, int32_t srcStep, float *dst, int32_t dstStep, HmppiSize roiSize, const float threshold[3], const float value[3], HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_8u_AC4R(const uint8_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, const uint8_t threshold[3], const uint8_t value[3], HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_16u_AC4R(const uint16_t *src, int32_t srcStep, uint16_t *dst, int32_t dstStep, HmppiSize roiSize, const uint16_t threshold[3], const uint16_t value[3], HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_16s_AC4R(const int16_t *src, int32_t srcStep, int16_t *dst, int32_t dstStep, HmppiSize roiSize, const int16_t threshold[3], const int16_t value[3], HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_32f_AC4R(const float *src, int32_t srcStep, float *dst, int32_t dstStep, HmppiSize roiSize, const float threshold[3], const float value[3], HmppCmpOp cmpOp);
- In-place thresholding for single-channel data:
HmppResult HMPPI_Threshold_Val_8u_C1IR(uint8_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, uint8_t threshold, uint8_t value, HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_16u_C1IR(uint16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, uint16_t threshold, uint16_t value, HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_16s_C1IR(int16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, int16_t threshold, int16_t value, HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_32f_C1IR(float *srcDst, int32_t srcDstStep, HmppiSize roiSize, float threshold, float value, HmppCmpOp cmpOp);
- In-place thresholding for multi-channel data:
HmppResult HMPPI_Threshold_GT_8u_C3IR(uint8_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, const uint8_t threshold[3]);
HmppResult HMPPI_Threshold_Val_8u_C3IR(uint8_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, const uint8_t threshold[3], const uint8_t value[3], HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_16u_C3IR(uint16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, const uint16_t threshold[3], const uint16_t value[3], HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_16s_C3IR(int16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, const int16_t threshold[3], const int16_t value[3], HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_32f_C3IR(float *srcDst, int32_t srcDstStep, HmppiSize roiSize, const float threshold[3], const float value[3], HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_8u_AC4IR(uint8_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, const uint8_t threshold[3], const uint8_t value[3], HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_16u_AC4IR(uint16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, const uint16_t threshold[3], const uint16_t value[3], HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_16s_AC4IR(int16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, const int16_t threshold[3], const int16_t value[3], HmppCmpOp cmpOp);
HmppResult HMPPI_Threshold_Val_32f_AC4IR(float *srcDst, int32_t srcDstStep, HmppiSize roiSize, const float threshold[3], const float value[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. |
Input/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. |
Range of the input data type |
Input |
Value |
Output pixel value for each pixel that satisfies the comparison condition ("greater than" or "less than"). In the case of multi-channel data, an array of values is used. |
Range of the input data type |
Input |
cmpOp |
Operation used to compare pixel values and the threshold. You can use the "less than" (HMPP_CMPLESS) or "greater than" (HMPP_CMPGREATER) comparison. |
HMPP_CMPLESS or HMPP_CMPGREATER |
Input |
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, dst, or srcDst is NULL. |
HMPP_STS_SIZE_ERR |
The value of roiSize is 0 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_NOT_SUPPORTED_MODE_ERR |
The comparison mode is not supported. |
HMPP_STS_ROI_ERR |
The value of roiSize.width is greater than the step. |
HMPP_STS_NO_ERR |
No error occurs. |
Example
#define BUFFER_SIZE_T 36
int ThresholValExample()
{
HmppiSize roi = { 3, 4 };
uint8_t src[BUFFER_SIZE_T] = { 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[BUFFER_SIZE_T] = {0};
uint8_t threshold[3] = {8, 8, 8};
uint8_t value[3] = {7, 7, 7};
int srcStep = 9 * sizeof(uint8_t);
int dstStep = 9 * sizeof(uint8_t);
HmppResult result = HMPPI_Threshold_Val_8u_C3R(src, srcStep, dst, dstStep, roi, threshold, value, HMPP_CMP_LT);
printf("result = %d \n dst = ", result);
if (result != HMPP_STS_NO_ERR) {
printf("result error: %d\n", result);
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 9; j++) {
printf("%4d ", dst[i * 9 + j]);
}
printf("\n");
}
return 0;
}
Output:
result = 0
dst = 1 4 8 13 16 20 18 28 32 18 30 35 0
1 4 8 13 16 20 18 28 32 18 30 35 0
1 4 8 13 16 20 18 28 32 18 30 35 0
0 0 0 0 0 0 0 0 0 0 0 0 0