summaryrefslogtreecommitdiff
path: root/integralimg.go
diff options
context:
space:
mode:
Diffstat (limited to 'integralimg.go')
-rw-r--r--integralimg.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/integralimg.go b/integralimg.go
index d9bd38f..17d3332 100644
--- a/integralimg.go
+++ b/integralimg.go
@@ -10,12 +10,40 @@ package integralimg
import (
"image"
+ "image/color"
"math"
)
// I is the Integral Image
type I [][]uint64
+func (i I) ColorModel() color.Model { return color.GrayModel }
+
+func (i I) Bounds() image.Rectangle {
+ return image.Rectangle {image.Point{0, 0}, image.Point{len(i[0]), len(i)}}
+}
+
+func (i I) At(x, y int) color.Color {
+ if !(image.Point{x, y}.In(i.Bounds())) {
+ return color.Gray{}
+ }
+
+ var oldx, oldy, oldxy uint64
+ oldx, oldy, oldxy = 0, 0, 0
+ if x > 0 {
+ oldx = i[y][x-1]
+ }
+ if y > 0 {
+ oldy = i[y-1][x]
+ }
+ if x > 0 && y > 0 {
+ oldxy = i[y-1][x-1]
+ }
+ orig := i[y][x] + oldxy - oldx - oldy
+
+ return color.Gray{uint8(orig)}
+}
+
// Sq contains an Integral Image and its Square
type WithSq struct {
Img I