summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example_test.go73
-rw-r--r--integralimg.go8
2 files changed, 73 insertions, 8 deletions
diff --git a/example_test.go b/example_test.go
new file mode 100644
index 0000000..8958557
--- /dev/null
+++ b/example_test.go
@@ -0,0 +1,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 integralimg_test
+
+import (
+ "fmt"
+ "image"
+ "image/draw"
+ _ "image/png"
+ "log"
+ "os"
+
+ "rescribe.xyz/integralimg"
+)
+
+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()
+ integral := integralimg.NewImage(b)
+ draw.Draw(integral, b, img, b.Min, draw.Src)
+ fmt.Printf("Sum: %d\n", integral.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()
+ integral := integralimg.NewImage(b)
+ draw.Draw(integral, b, img, b.Min, draw.Src)
+ fmt.Printf("Mean: %f\n", integral.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()
+ integral := integralimg.NewImage(b)
+ sqIntegral := integralimg.NewSqImage(b)
+ draw.Draw(integral, b, img, b.Min, draw.Src)
+ draw.Draw(sqIntegral, b, img, b.Min, draw.Src)
+ mean, stddev := integralimg.MeanStdDev(*integral, *sqIntegral, b)
+ fmt.Printf("Mean: %f, Standard Deviation: %f\n", mean, stddev)
+ // Output:
+ // Mean: 54677.229042, Standard Deviation: 21643.721672
+}
diff --git a/integralimg.go b/integralimg.go
index 3585703..6cf3a25 100644
--- a/integralimg.go
+++ b/integralimg.go
@@ -7,14 +7,6 @@
// sum of pixels to the left and above each pixel, which can make
// several common image processing operations much faster.
//
-// integralimg.Image and integralimg.SqImage fully implement the
-// image.Image and image/draw.Draw interfaces, and hence can be
-// used like so:
-//
-// img, _, err := image.Decode(f)
-// integral := integralimg.NewImage(b)
-// draw.Draw(integral, b, img, b.Min, draw.Src)
-//
// The Sum(), Mean() and MeanStdDev() functions provided for the
// integral versions of Images significantly speed up many common
// image processing operations.