Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

answer_22.cpp中的标准差计算 #26

Open
beiluo97 opened this issue Apr 27, 2020 · 1 comment
Open

answer_22.cpp中的标准差计算 #26

beiluo97 opened this issue Apr 27, 2020 · 1 comment

Comments

@beiluo97
Copy link

  // get sum
  for (int y = 0; y < height; y++){
    for (int x = 0; x < width; x++){
      for (int c = 0; c < 3; c++){
        val = (float)img.at<cv::Vec3b>(y, x)[c];
        sum += val;
        squared_sum += (val * val);
      }
    }
  }

  // get standard deviation
  m = sum / (height * width * channel);
  s = sqrt(squared_sum / (height * width * channel) - m * m);

这一部分的均值计算是没有错的,但是,在计算标准差时,怎么能直接把所有rgb值的平方加起来算均值减去m^2?
https://pdfs.semanticscholar.org/fee0/d0c91442d465f343af18b5fce8aeff594d02.pdf
参考文章中STANDARD DEVIATION计算,应该是先计算出均值之后算每个值平方减去均值的平方再开根号。

@luzhenzheng
Copy link

参考文章中STANDARD DEVIATION计算,应该是先计算出均值之后算每个值平方减去均值的平方再开根号。

方差应该是E[(x-mu)^2]
应该是每个值 减去均值 得到的差求平方 然后把这些差的平方累加起来再求平均

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants