Threshold_LTValGTVal
Performs thresholding on pixels in an image using two specified levels thresholdLT and thresholdGT. Pixel values in the source image are compared to these levels. If the pixel value is less than thresholdLT, the corresponding output pixel is set to valueLT. If the pixel value is greater than thresholdGT, the output pixel is set to valueGT. Otherwise, it is set to the source pixel value. For images with multi-channel data, you need to set comparison conditions for each channel.
The formula is as follows:

The function interface is declared as follows:
- Thresholding for single-channel data:
HmppResult HMPPI_Threshold_LTValGTVal_8u_C1R(const uint8_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, uint8_t thresholdLT, uint8_t valueLT, uint8_t thresholdGT, uint8_t valueGT);
HmppResult HMPPI_Threshold_LTValGTVal_16u_C1R(const uint16_t *src, int32_t srcStep, uint16_t *dst, int32_t dstStep, HmppiSize roiSize, uint16_t thresholdLT, uint16_t valueLT, uint16_t thresholdGT, uint16_t valueGT);
HmppResult HMPPI_Threshold_LTValGTVal_16s_C1R(const int16_t *src, int32_t srcStep, int16_t *dst, int32_t dstStep, HmppiSize roiSize, int16_t thresholdLT, int16_t valueLT, int16_t thresholdGT, int16_t valueGT);
HmppResult HMPPI_Threshold_LTValGTVal_32f_C1R(const float *src, int32_t srcStep, float *dst, int32_t dstStep, HmppiSize roiSize, float thresholdLT, float valueLT, float thresholdGT, float valueGT);
- Thresholding for multi-channel data:
HmppResult HMPPI_Threshold_LTValGTVal_8u_C3R(const uint8_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, const uint8_t thresholdLT[3], const uint8_t valueLT[3], const uint8_t thresholdGT[3], const uint8_t valueGT[3]);
HmppResult HMPPI_Threshold_LTValGTVal_16u_C3R(const uint16_t *src, int32_t srcStep, uint16_t *dst, int32_t dstStep, HmppiSize roiSize, const uint16_t thresholdLT[3], const uint16_t valueLT[3], const uint16_t thresholdGT[3], const uint16_t valueGT[3]);
HmppResult HMPPI_Threshold_LTValGTVal_16s_C3R(const int16_t *src, int32_t srcStep, int16_t *dst, int32_t dstStep HmppiSize roiSize, const int16_t thresholdLT[3], const int16_t valueLT[3] const int16_t thresholdGT[3], const int16_t valueGT[3]);
HmppResult HMPPI_Threshold_LTValGTVal_32f_C3R(const float *src, int32_t srcStep, float *dst, int32_t dstStep HmppiSize roiSize, const float thresholdLT[3], const float valueLT[3] const float thresholdGT[3], const float valueGT[3]);
HmppResult HMPPI_Threshold_LTValGTVal_8u_AC4R(const uint8_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep HmppiSize roiSize, const uint8_t thresholdLT[3], const uint8_t valueLT[3] const uint8_t thresholdGT[3], const uint8_t valueGT[3]);
HmppResult HMPPI_Threshold_LTValGTVal_16u_AC4R(const uint16_t *src, int32_t srcStep, uint16_t *dst, int32_t dstStep HmppiSize roiSize, const uint16_t thresholdLT[3] const uint16_t valueLT[3], const uint16_t thresholdGT[3] const uint16_t valueGT[3]);
HmppResult HMPPI_Threshold_LTValGTVal_16s_AC4R(const int16_t *src, int32_t srcStep, int16_t *dst, int32_t dstStep HmppiSize roiSize, const int16_t thresholdLT[3] const int16_t valueLT[3], const int16_t thresholdGT[3] const int16_t valueGT[3]);
HmppResult HMPPI_Threshold_LTValGTVal_32f_AC4R(const float *src, int32_t srcStep, float *dst, int32_t dstStep HmppiSize roiSize, const float thresholdLT[3], const float valueLT[3] const float thresholdGT[3], const float valueGT[3]);
- In-place thresholding for single-channel data:
HmppResult HMPPI_Threshold_LTValGTVal_8u_C1IR(uint8_t *srcDst, int32_t srcDstStep, HmppiSize roiSize uint8_t thresholdLT, uint8_t valueLT, uint8_t thresholdGT uint8_t valueGT);
HmppResult HMPPI_Threshold_LTValGTVal_16u_C1IR(uint16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize uint16_t thresholdLT, uint16_t valueLT, uint16_t thresholdGT uint16_t valueGT);
HmppResult HMPPI_Threshold_LTValGTVal_16s_C1IR(int16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize int16_t thresholdLT, int16_t valueLT, int16_t thresholdGT int16_t valueGT);
HmppResult HMPPI_Threshold_LTValGTVal_32f_C1IR(float *srcDst, int32_t srcDstStep, HmppiSize roiSize float thresholdLT, float valueLT, float thresholdGT, float valueGT);
- In-place thresholding for multi-channel data:
HmppResult HMPPI_Threshold_LTValGTVal_8u_C3IR(uint8_t *srcDst, int32_t srcDstStep, HmppiSize roiSize const uint8_t thresholdLT[3], const uint8_t valueLT[3] const uint8_t thresholdGT[3], const uint8_t valueGT[3]);
HmppResult HMPPI_Threshold_LTValGTVal_16u_C3IR(uint16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize const uint16_t thresholdLT[3], const uint16_t valueLT[3] const uint16_t thresholdGT[3], const uint16_t valueGT[3]);
HmppResult HMPPI_Threshold_LTValGTVal_16s_C3IR(int16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize const int16_t thresholdLT[3], const int16_t valueLT[3] const int16_t thresholdGT[3], const int16_t valueGT[3]);
HmppResult HMPPI_Threshold_LTValGTVal_32f_C3IR(float *srcDst, int32_t srcDstStep, HmppiSize roiSize const float thresholdLT[3], const float valueLT[3] const float thresholdGT[3], const float valueGT[3]);
HmppResult HMPPI_Threshold_LTValGTVal_8u_AC4IR(uint8_t *srcDst, int32_t srcDstStep, HmppiSize roiSize const uint8_t thresholdLT[3], const uint8_t valueLT[3] const uint8_t thresholdGT[3], const uint8_t valueGT[3]);
HmppResult HMPPI_Threshold_LTValGTVal_16u_AC4IR(uint16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize const uint16_t thresholdLT[3], const uint16_t valueLT[3] const uint16_t thresholdGT[3], const uint16_t valueGT[3]);
HmppResult HMPPI_Threshold_LTValGTVal_16s_AC4IR(int16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize const int16_t thresholdLT[3], const int16_t valueLT[3] const int16_t thresholdGT[3], const int16_t valueGT[3]);
HmppResult HMPPI_Threshold_LTValGTVal_32f_AC4IR(float *srcDst, int32_t srcDstStep, HmppiSize roiSize const float thresholdLT[3], const float valueLT[3] const float thresholdGT[3], const float valueGT[3]);
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 images (for in-place operations) |
The value cannot be NULL. |
Input/Output |
srcDstStep |
Distance between starts of consecutive lines in the source and destination images (in-place operation), 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 |
thresholdLT |
Lower threshold value to be used for each pixel |
Range of the input data type |
Input |
valueLT |
Lower output value to be set for each pixel if the source pixel value is less than the lower threshold value |
The value must be zero or a positive integer. |
Input |
thresholdGT |
Upper threshold value to be used for each pixel |
Range of the input data type |
Input |
valueGT |
Upper output value to be set for each pixel if the source pixel value is greater than the upper threshold value |
The value must be zero or a positive integer. |
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 0 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 |
The value of roiSize.width is greater than the step. |
HMPP_STS_THRESHOLD_ERR |
The value of thresholdLT is less than that of thresholdGT. |
HMPP_STS_NO_ERR |
No error occurs. |
Example
#define BUFFER_SIZE_T 36
int ThresholdLTValGTValExample()
{
HmppiSize roi = { 3, 4 };
uint16_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};
uint16_t dst[BUFFER_SIZE_T] = {0};
uint16_t thresholdLT[3] = {2, 2, 2};
uint16_t valueLT[3] = {3, 3, 3};
uint16_t thresholdGT[3] = {9, 9, 9};
uint16_t valueGT[3] = {8, 8, 8};
int srcStep = 9 * sizeof(uint16_t);
int dstStep = 9 * sizeof(uint16_t);
HmppResult result = HMPPI_Threshold_LTValGTVal_16u_C3R(src, srcStep, dst, dstStep, roi, thresholdLT, valueLT, thresholdGT, valueGT);
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 = 3 2 4 8 8 8 4 2 3
3 2 4 8 8 8 4 2 3
3 2 4 8 8 8 4 2 3
3 2 4 8 8 8 4 2 3