OpenCV规范化函数,结果不总和为一

Joh*_* Jo 1 c++ opencv normalize

我在下面的代码中使用normalize函数.我的理解是,对直方图进行标准化会导致这些箱子总和为一个?但是当我把它们全部添加起来时,我会得到比一个更高的结果.我不知道我做错了什么或者误解了这个功能是做什么的?

//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;
Run Code Online (Sandbox Code Playgroud)

小智 5

归一化数组不总和为1,但组分的平方和的平方根等于1,向量中的Fe:

在以下情况下对其进行归一化:sqrt(x ^ 2 + y ^ 2 + z ^ 2)= 1

*这适用于矢量

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