mirror of https://bitbucket.org/ausocean/av.git
add standard deviation function
This commit is contained in:
parent
88f0716f7b
commit
07c8d4774a
|
@ -34,6 +34,17 @@ import (
|
|||
"gonum.org/v1/plot/vg"
|
||||
)
|
||||
|
||||
// standarDeviation will return the standard deviation of a float slice
|
||||
func standarDeviation(slice []float64) float64 {
|
||||
mean := average(slice)
|
||||
variance := 0.0
|
||||
|
||||
for _, i := range slice {
|
||||
variance += math.Pow(i-mean, 2.0)
|
||||
}
|
||||
return math.Sqrt(variance / float64(len(slice)))
|
||||
}
|
||||
|
||||
// Normalize values in a slice between 0 and 1.
|
||||
func normalize(slice []float64) []float64 {
|
||||
max := -math.MaxFloat64
|
||||
|
|
|
@ -142,7 +142,7 @@ func (ts TurbiditySensor) minMax(img gocv.Mat, xStart, yStart, xEnd, yEnd int) (
|
|||
for j := yStart; j < yEnd; j++ {
|
||||
value := float64(img.GetUCharAt(i, j))
|
||||
|
||||
// Check max/min conditions, zero values are ignored.
|
||||
// Check max/min conditions, zero values are ignoredt to avoid divison by 0.
|
||||
if value > max && value != 0.0 {
|
||||
max = value
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ func TestImages(t *testing.T) {
|
|||
// Evaluate camera burst.
|
||||
sample_result, err := ts.Evaluate(imgs[i])
|
||||
if err != nil {
|
||||
t.Fatalf("evaluation Failed: %w", err)
|
||||
t.Fatalf("evaluation Failed: %v", err)
|
||||
}
|
||||
|
||||
// Add the average result from camera burst.
|
||||
|
@ -86,7 +86,7 @@ func TestImages(t *testing.T) {
|
|||
// Plot the final results.
|
||||
err = plotResults(results.Turbidity, normalize(results.Sharpness), normalize(results.Contrast))
|
||||
if err != nil {
|
||||
t.Fatalf("plotting Failed: %w", err)
|
||||
t.Fatalf("plotting Failed: %v", err)
|
||||
}
|
||||
|
||||
t.Logf("Sharpness: %v", results.Sharpness)
|
||||
|
|
Loading…
Reference in New Issue