summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2020-07-22 17:07:45 +0100
committerNick White <git@njw.name>2020-07-22 17:07:45 +0100
commit43d0e6116e25578d1b76cf6ed8c93cc73f663d05 (patch)
tree2383d4aa2431d3e5993ff7ad9aac8db91621b9a9
parentf433a5c8405db5846f62fac13bd9343e180d8fd0 (diff)
Implement image.Image interface
-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