matlab to C++/openCV 归一化函数
matlab to C++/openCV normalization function
这是我的matlab代码:
imageData = imageData ./ toolbox.c3d.p.tprctile(imageData(xy),99.2);
imageData(imageData>1) = 1;
这是我的 openCV/C++ 代码,矩阵 dst 是一个 openCV 矩阵
cv::垫子 dst
std::vector<float> result;
for (std::vector<int>::iterator it = index.begin() ; it != index.end(); ++it)
{
int ind = *it;
float temp = dst.at<float>(ind - 1);
result.push_back(temp);
}
float divider = tprctile(result,99.2);
dst = dst/ divider;
百分位数的效用函数
float Utils::tprctile(std::vector<float> channel, double pt)
{
std::sort(channel.begin(),channel.end());
int ptInd = Utilities::MatlabRound (pt/100 * channel.size() );
return channel[ptInd];
// Matlab code
// function val = tprctile(data, pt)
// data = sort(data);
// ptInd = round( pt/100 * length(data) );
// val = data(ptInd);
}
我的问题是关于imageData(imageData>1) = 1
实现此功能的最有效方法是什么 - 我当然可以像以前一样遍历 DST。有没有更好的方法?
你想要的是
用cv::threshold截断图像。
以下内容应满足您的要求:
cv::threshold(dst, dst, 1, 1, CV_THRESH_TRUNC);
这将截断所有大于 1 的值,并将结果存储在 dst 中。
http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html?highlight=threshold#threshold
这就是
我目前正在做的事情
int matrixSize = dst.rows *dst.cols;
cv::MatConstIterator_<float> it = dst.begin<float>(), it_end = dst.end<float>();
for(int i = 0 ; i < matrixSize ; ++i, ++it)
{
float value = *it;
if(value > 1.0)
{
dst.at<float>(i) = 1.0;
}
}
相关文章:
- C++ OpenCV 卡尔曼滤波器构造函数错误
- 如何将 c++ get 函数代码转换为 opencv 算法中使用的 python
- OpenCV imwrite 函数导致'undefined symbol'
- OpenCV 函数 cv::remap() 的执行时间更长,当程序在两者之间进入睡眠状态时
- 如果函数使用 OPENCV Mat 作为输入,如何编写头文件?
- C++ OpenCV Randu 函数抛出'Integer division by zero'
- c++调用opencv相关函数,并且被打包到dll中,c#无法调用它
- 在OpenCV_core310.dll中使用findContours函数时,OpenCV引发未处理的异常
- 为什么OpenCV Templete匹配函数根本不准确
- OpenCV 与 C++,使用 cv::utils::fs::glob() 函数
- C++中相同的CV函数(OpenCV)
- OpenCV 如何确定具有不同参数的函数的 python 绑定?
- openCV Mat 中的值在自定义类构造函数中设置后不会保留
- 将自适应阈值应用于范围函数 opencv c++
- 双曲最终概率密度函数 Opencv
- 使用标准化函数/OPENCV和C 获取内存分配错误
- 将Mat传递给JNI函数-OpenCV
- 删除Mat int函数(opencv)
- 我不能使用函数'OpenCV的放置文本
- 鼠标回调函数 OpenCV