From 43d0e6116e25578d1b76cf6ed8c93cc73f663d05 Mon Sep 17 00:00:00 2001 From: Nick White Date: Wed, 22 Jul 2020 17:07:45 +0100 Subject: Implement image.Image interface --- integralimg.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'integralimg.go') 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 -- cgit v1.2.1-24-ge1ad