中文
注册
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助

ComputeThreshold_Otsu

计算Otsu阈值的值。计算公式为:

w0:前景点所占的比例。

wl:背景点所占比例(1 - w0)。

u0:前景点灰度值。

u1:背景点的灰度值。

u:图像整体的均值。

函数接口声明如下:

单通道数据的阈值操作

HmppResult HMPPI_ComputeThreshold_Otsu_8u_C1R(const uint8_t* src, int32_t srcStep, HmppiSize roiSize, uint8_t* threshold);

参数

参数名

描述

取值范围

输入/输出

src

指向源图像感兴趣区域的指针。

非空

输入

srcStep

源图像中连续行起点之间的距离(以字节为单位)。

非空

输入

roiSize

源和目标图像感兴趣区域的大小(以像素为单位)。

roiSize.width∈(0, INT_MAX],roiSize.height∈(0, INT_MAX]

输入

threshold

指向Otsu阈值的指针。

输入数据类型的范围

输出

返回值

  • 成功:返回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_ROI_ERR

roiSize.width大于步长。

示例

#define BUFFER_SIZE 36
int ComputeThreshold_Ostu()
{
    HmppiSize roi = { 9, 4 };
    const uint8_t src[BUFFER_SIZE] = { 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 threshold;
    int32_t srcStep = 9 * sizeof(uint8_t);
    HmppResult result = HMPPI_ComputeThreshold_Otsu_8u_C1R(src, srcStep, roi, &threshold);

    printf("result = %d \n dst = ", result);
    if (result != HMPP_STS_NO_ERR) {
        printf("result error: %d\n", result);
    }
    printf("%d\n", threshold);
    return 0;
}

运行结果:

result = 0
dst = 4