mirror of https://bitbucket.org/ausocean/av.git
add standard deviation function
This commit is contained in:
parent
00e1390893
commit
4d02d9ae47
|
@ -34,6 +34,17 @@ import (
|
||||||
"gonum.org/v1/plot/vg"
|
"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.
|
// Normalize values in a slice between 0 and 1.
|
||||||
func normalize(slice []float64) []float64 {
|
func normalize(slice []float64) []float64 {
|
||||||
max := -math.MaxFloat64
|
max := -math.MaxFloat64
|
||||||
|
|
|
@ -141,7 +141,7 @@ func (ts TurbiditySensor) minMax(img gocv.Mat, xStart, yStart, xEnd, yEnd int) (
|
||||||
for j := yStart; j < yEnd; j++ {
|
for j := yStart; j < yEnd; j++ {
|
||||||
value := float64(img.GetUCharAt(i, 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 {
|
if value > max && value != 0.0 {
|
||||||
max = value
|
max = value
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ func TestImages(t *testing.T) {
|
||||||
// Evaluate camera burst.
|
// Evaluate camera burst.
|
||||||
sample_result, err := ts.Evaluate(imgs[i])
|
sample_result, err := ts.Evaluate(imgs[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("evaluation Failed: %w", err)
|
t.Fatalf("evaluation Failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the average result from camera burst.
|
// Add the average result from camera burst.
|
||||||
|
@ -86,7 +86,7 @@ func TestImages(t *testing.T) {
|
||||||
// Plot the final results.
|
// Plot the final results.
|
||||||
err = plotResults(results.Turbidity, normalize(results.Sharpness), normalize(results.Contrast))
|
err = plotResults(results.Turbidity, normalize(results.Sharpness), normalize(results.Contrast))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("plotting Failed: %w", err)
|
t.Fatalf("plotting Failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("Sharpness: %v", results.Sharpness)
|
t.Logf("Sharpness: %v", results.Sharpness)
|
||||||
|
|
Loading…
Reference in New Issue