How is the standard deviation computed?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How is the standard deviation computed?

Mohamed Tleis
Dear Members,

I tried to compute the standard deviation manually for my ROIs, and
compared it to the results obtained by imageJ itself; and I noticed a small
difference (around 0.01) in the results between my values and imageJ's
standard deviation; the mean of gray values that I calculated was exactly
the same as that of imageJ; and the standard deviation = Sqrt (Variance),
where variance = [Sum(grayValues-mean)^2]/(number of pixels inside ROI).

I am interested in seeing the code on how the standard deviation is
computed, to know where this difference is coming from.

Best Regards,
Mohamed Tleis
Reply | Threaded
Open this post in threaded view
|

Re: How is the standard deviation computed?

John Minter
Try dividing by (n-1) pixels because that is the correct number of
degrees of freedom. See
http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/

Best regards,
John

On Fri, Mar 16, 2012 at 12:55 PM, Mohammed Tlais <[hidden email]> wrote:

> Dear Members,
>
> I tried to compute the standard deviation manually for my ROIs, and
> compared it to the results obtained by imageJ itself; and I noticed a small
> difference (around 0.01) in the results between my values and imageJ's
> standard deviation; the mean of gray values that I calculated was exactly
> the same as that of imageJ; and the standard deviation = Sqrt (Variance),
> where variance = [Sum(grayValues-mean)^2]/(number of pixels inside ROI).
>
> I am interested in seeing the code on how the standard deviation is
> computed, to know where this difference is coming from.
>
> Best Regards,
> Mohamed Tleis
Reply | Threaded
Open this post in threaded view
|

Re: How is the standard deviation computed?

Michael Schmid
In reply to this post by Mohamed Tleis
Hi Mohamed,

the standard deviation is calculated as

  sqrt( (sum of squared pixel values - (sum of pixel values)^2 / n) / (n - 1) )

The (n-1) in the denominator might be the reason for the difference.

Sometimes one finds the equation with n instead of n-1 in the denominator. That would be the 'population standard deviation', which is justified if there can't be any more data than the pixels that you have in the ROI.
The denominator n-1 is appropriate if there could be more data, e.g. because the standard deviation is due to detector noise (one could take more and more images), or if you want to calculate the error bars of the mean value.

As usual, it's nicely explained in the Wikipedia,
     http://en.wikipedia.org/wiki/Standard_deviation

Michael
________________________________________________________________
On Mar 16, 2012, at 17:55, Mohammed Tlais wrote:

> Dear Members,
>
> I tried to compute the standard deviation manually for my ROIs, and
> compared it to the results obtained by imageJ itself; and I noticed a small
> difference (around 0.01) in the results between my values and imageJ's
> standard deviation; the mean of gray values that I calculated was exactly
> the same as that of imageJ; and the standard deviation = Sqrt (Variance),
> where variance = [Sum(grayValues-mean)^2]/(number of pixels inside ROI).
>
> I am interested in seeing the code on how the standard deviation is
> computed, to know where this difference is coming from.
>
> Best Regards,
> Mohamed Tleis