Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes Issue 27 : Image statistics reports negative mean value for big
images
Updated calculation of mean in AForge.Math.Statistics to use double
precision numbers internally to avoid integers' overflow.
  • Loading branch information
anders9ustafsson committed Apr 24, 2014
1 parent fa1677f commit 2fe6145
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/Math/Statistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public static class Statistics
public static double Mean( int[] values )
{
int hits;
long total = 0;
double total = 0;
double mean = 0;

// for all values
for ( int i = 0, n = values.Length; i < n; i++ )
{
hits = values[i];
// accumulate mean
mean += i * hits;
mean += (double) i * hits;
// accumalate total
total += hits;
}
Expand Down

0 comments on commit 2fe6145

Please sign in to comment.