1

我在下面的代码中使用了 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;
4

1 回答 1

5

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

它是标准化的,当:sqrt(x^2 + y^2 + z^2) = 1

*这适用于矢量

在 OpenCV - histogram - normalize 在这里描述OpenCV histogram normalize,应该清楚(在阅读规范后)它不必总和为 1

于 2012-02-12T15:07:39.530 回答