---
title: Threshold_LT
description: "对图像中的像素与阈值进行比较，小于阈值的设置为阈值。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/251RC1/accel/kunpengaccel_hmpp_06_0193.html
sourcePath: /source/zh/kunpengboostkithistory/251RC1/accel/kunpengaccel_hmpp_06_0193.html
indexId: 85acad5e35f67e381ab3853a41107bc793f03958c1a7506fcc2bbd735bf76d4377
---
# Threshold_LT

对图像中的像素与阈值进行比较，小于阈值的设置为阈值。

大于操作，即level是源向量的下边界。计算公式为：


函数接口声明如下：

- 单通道数据的阈值操作：
  HmppResult HMPPI_Threshold_LT_8u_C1R(const uint8_t* src, int32_t srcStep, uint8_t* dst, int32_t dstStep, HmppiSize roiSize, uint8_t threshold);

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

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

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

- 多通道数据的阈值操作：
  HmppResult HMPPI_Threshold_LT_8u_C3R(const uint8_t *src, int32_t srcStep, uint8_t*dst, int32_t dstStep, HmppiSize roiSize, const uint8_t threshold[3]);

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

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

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

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

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

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

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

- 单通道数据的原址阈值操作：
  HmppResult HMPPI_Threshold_LT_8u_C1IR(uint8_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, uint8_t threshold);

  HmppResult HMPPI_Threshold_LT_16u_C1IR(uint16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, uint16_t threshold);

  HmppResult HMPPI_Threshold_LT_16s_C1IR(int16_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, int16_t threshold);

  HmppResult HMPPI_Threshold_LT_32f_C1IR(float *srcDst, int32_t srcDstStep, HmppiSize roiSize, float threshold);

- 多通道数据的原址阈值操作：
  HmppResult HMPPI_Threshold_LT_8u_C3IR(uint8_t *srcDst, int32_t srcDstStep, HmppiSize roiSize, const uint8_t threshold[3]);

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

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

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

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

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

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

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


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| src | 指向源图像感兴趣区域的指针。 | 非空。 | 输入 |
| srcStep | 源图像中连续行起点之间的距离（以字节为单位）。 | 非空。 | 输入 |
| dst | 指向目标图像感兴趣区域的指针。 | 非空。 | 输出 |
| dstStep | 目标图像中连续行的起点之间的距离（以字节为单位）。 | 大于0。 | 输入 |
| srcDst | 指向源和目标图像感兴趣区域的指针（用于原址操作）。 | 非空。 | 输入/输出 |
| srcDstStep | 原址操作的源图像和目标图像中连续行起点之间的距离（以字节为单位）。 | 大于0。 | 输入 |
| roiSize | 源和目标图像感兴趣区域的大小（以像素为单位）。 | roiSize.width∈(0, INT\_MAX]，roiSize.height∈(0, INT\_MAX] | 输入 |
| threshold | 每个像素要使用的阈值水平值；多通道数据下，使用每个颜色通道的阈值数组。 | 任意值。 | 输入 |


#### 返回值

- 成功：返回HMPP_STS_NO_ERR。
- 失败：返回错误码。


#### 错误码

| 错误码 | 描述 |
| --- | --- |
| HMPP\_STS\_NULL\_PTR\_ERR | src、dst、srcDst中存在空指针。 |
| HMPP\_STS\_SIZE\_ERR | roiSize的width、height存在零或负值。 |
| HMPP\_STS\_STEP\_ERR | srcStep、dstStep、srcDstStep中存在零或负值。 |
| HMPP\_STS\_NOT\_EVEN\_STEP\_ERR | srcStep、dstStep不能被src、dst所属数据类型的字节长度整除的错误条件。 |
| HMPP\_STS\_ROI\_ERR | roiSize.width > 步长。 |


#### 示例

```
#define BUFFER_SIZE_T 52
int ThresholdLTExample(){
HmppiSize roi = {4,3};
uint8_t src[BUFFER_SIZE_T] = {  1, 4, 8, 13, 16, 20, 24, 28, 32, 36, 40, 44, 48,
1, 4, 8, 13, 16, 20, 24, 28, 32, 36, 40, 44, 48,
1, 4, 8, 13, 16, 20, 24, 28, 32, 36, 40, 44, 48,
1, 4, 8, 13, 16, 20, 24, 28, 32, 36, 40, 44, 48};
uint8_t dst[BUFFER_SIZE_T] = {0};
uint8_t threshold[3] = {18,30,35};
int32_t srcStep=13*sizeof(uint8_t);
int32_t dstStep=13*sizeof(uint8_t);
HmppResult result = HMPPI_Threshold_LT_8u_C3R(src, srcStep, dst, dstStep, roi, threshold);
printf("result = %d \ndst =", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
for (int i = 0; i < 4; i++){
for (int j = 0; j < 13; j++){
printf("%4d ", dst[i * 13 + j]);
}
printf("\n");
}
return 0;
}
```

运行结果：

```
result = 0
dst = 18 30 35 18 30 35 24 30 35 36 40 44 0
18 30 35 18 30 35 24 30 35 36 40 44 0
18 30 35 18 30 35 24 30 35 36 40 44 0
0  0  0  0  0  0  0  0  0  0  0  0 0
```
