OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Mon, 13 Jan 2014 07:33:09 -0600Standard deviation from discrete valueshttp://answers.opencv.org/question/26422/standard-deviation-from-discrete-values/I want to calculate standard deviation for every pixel in image, that I will get from web camera. So I will have many samples for every pixel.
Is possible to calculate the standard deviation of discrete values, without knowing the probabilities of the values (without keeping the last 100 frames into the memory)?
Mon, 13 Jan 2014 03:18:37 -0600http://answers.opencv.org/question/26422/standard-deviation-from-discrete-values/Answer by Adi for <p>I want to calculate standard deviation for every pixel in image, that I will get from web camera. So I will have many samples for every pixel. </p>
<p>Is possible to calculate the standard deviation of discrete values, without knowing the probabilities of the values (without keeping the last 100 frames into the memory)?</p>
http://answers.opencv.org/question/26422/standard-deviation-from-discrete-values/?answer=26448#post-id-26448Yes.
Std-dev is [the root of the variance](http://en.wikipedia.org/wiki/Standard_deviation#Definition_of_population_values). The variance can be defined as:
***the-mean-of-square-values** minus **the-square-of-the-value-mean***.
Thus, you can keep 3 running values:
1. The number of processed pixels: `n`;
2. The sums of all the pixels - `m_x`;
3. The sum of the squares of all the pixels `m_xx`.
The variance is then: `float var = (m_xx - m_x)/n;`
The std-dev is thus: `float stddev = sqrt(var);`.Mon, 13 Jan 2014 07:33:09 -0600http://answers.opencv.org/question/26422/standard-deviation-from-discrete-values/?answer=26448#post-id-26448