c++ - opencv中 'imquantize'函数的实现

标签 c++ matlab opencv

我正在尝试使用 opencv 实现 Matlab 函数 imquantize。我应该使用哪个 opencv 阈值函数来实现 Matlab 函数 multithresh?完成阈值处理后,如何根据阈值标记像素?这是实现 imquantize 的正确方法吗?我应该在代码中包含任何其他功能吗?

最佳答案

有基于OpenCV的实现here ,您应该从哪里得到这个想法:

cv::Mat
imquantize(const cv::Mat& in, const arma::fvec& thresholds) {
    BOOST_ASSERT_MSG(cv::DataType<float>::type == in.type(), "input is not of type float");

    cv::Mat index(in.size(), in.type(), cv::Scalar::all(1));
    for (int i = 0; i < thresholds.size() ; i++) {
        cv::Mat temp = (in > thresholds(i)) / 255;
        temp.convertTo(temp, cv::DataType<float>::type);
        index += temp;
    }

    return index;
}

已更新:thresholds 是浮点阈值的 vector (均匀分布到您要量化的# of levels[0, 1]) 内。 检查 the code snippet使用方法:

const float step = 1./levels[i];
arma::fvec thresh = arma::linspace<arma::fvec>(step, 1.-step, levels[i]-1);
channels[i] = imquantize(channels[i], thresh);

关于c++ - opencv中 'imquantize'函数的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32110267/

相关文章:

c++ - Gem5 中的 UART 通信与 ARM 裸机

c++ - 带有 std::array 的矩阵类

java - 将 C++ 对象返回给 Java

string - 遍历 MATLAB 中的字符串列表

python - 相机标定opencv python鸟瞰视角变换

c++ - 需要帮助为 Arduino 创建无限数组 (c/c++)

matlab 将绘图导出为矢量格式

Matlab 只是说有一个错误,但我没有看到。我如何知道更多关于错误的信息

c++ - opencv/c++ 中适当的阈值函数

image-processing - 如何使用opencv查找凸性缺陷?