我在下面的代码中使用了规范化函数。我的理解是,对直方图进行归一化会导致 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/