1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
// Copyright 2020 Nick White.
// Use of this source code is governed by the GPLv3
// license that can be found in the LICENSE file.
package integral_test
import (
"fmt"
"image"
"image/draw"
_ "image/png"
"log"
"os"
"rescribe.xyz/integral"
)
func ExampleImage_Sum() {
f, err := os.Open("testdata/in.png")
if err != nil {
log.Fatal(err)
}
defer f.Close()
img, _, err := image.Decode(f)
if err != nil {
log.Fatal(err)
}
b := img.Bounds()
in := integral.NewImage(b)
draw.Draw(in, b, img, b.Min, draw.Src)
fmt.Printf("Sum: %d\n", in.Sum(b))
// Output:
// Sum: 601340165
}
func ExampleImage_Mean() {
f, err := os.Open("testdata/in.png")
if err != nil {
log.Fatal(err)
}
defer f.Close()
img, _, err := image.Decode(f)
if err != nil {
log.Fatal(err)
}
b := img.Bounds()
in := integral.NewImage(b)
draw.Draw(in, b, img, b.Min, draw.Src)
fmt.Printf("Mean: %f\n", in.Mean(b))
// Output:
// Mean: 54677.229042
}
func ExampleMeanStdDev() {
f, err := os.Open("testdata/in.png")
if err != nil {
log.Fatal(err)
}
defer f.Close()
img, _, err := image.Decode(f)
if err != nil {
log.Fatal(err)
}
b := img.Bounds()
in := integral.NewImage(b)
sq := integral.NewSqImage(b)
draw.Draw(in, b, img, b.Min, draw.Src)
draw.Draw(sq, b, img, b.Min, draw.Src)
mean, stddev := integral.MeanStdDev(*in, *sq, b)
fmt.Printf("Mean: %f, Standard Deviation: %f\n", mean, stddev)
// Output:
// Mean: 54677.229042, Standard Deviation: 21643.721672
}
|