c++ - OpenCV 归一化函数,结果总和不为一

标签 c++ opencv normalize

我在下面的代码中使用了规范化函数。我的理解是,对直方图进行归一化会导致 bin 总和为 1?但是当我把它们全部加起来时,我得到的结果总是比一个高。我不知道是我做错了什么还是误解了函数的作用?

//read in image
Mat img = imread("image.jpg",1);
vector<Mat> planes;
split(img, planes);

//calculate hist
MatND hist;
int nbins = 256; // hold 256 levels
int hsize[] = { nbins }; // one dimension
float range[] = { 0, 255 };
const float *ranges[] = { range };
int chnls[] = {0};
calcHist(&planes[0], 1, chnls, Mat(), hist,1,hsize,ranges);

//normalise
normalize(hist,hist,1);

float tot = 0;
for( int n = 0;n < nbins; n++ )
    {
        float binVal = hist.at<float>(n);
        tot+=binVal;
    }
cout<<tot;

最佳答案

归一化数组总和不为1,但分量平方和的平方根等于1,F.e.在 vector 中:

归一化,当: 平方根(x^2 + y^2 + z^2)= 1

*这适用于 vector

在 OpenCV 中 - 直方图 - 规范化在此处描述 OpenCV histogram normalize ,应该清楚(在阅读规范后)它不必总和为 1

关于c++ - OpenCV 归一化函数,结果总和不为一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9249798/

相关文章:

python - 如何在 python 中使用 NaN 值规范化数据

c++ - C++标点符号的使用逻辑是什么?

c++ - 创建基于网格的数组

python - 使用 Opencv 关闭 python 代码后如何保存轨迹栏值?

c - OpenCV : How to use cvWaitKey() form a different thread other than the one created the window?

python - 用权重标准化排名分数

C++ 如何用模板类调用模板函数?

c++ - 对象的协变返回类型

python - 无法在 Ubuntu 16.04 上的 python 中使用 OpenCV

c# - 如何在 'for' 循环中从 0.0 正确迭代到 1.0?