summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2020-07-29 18:18:40 +0100
committerNick White <git@njw.name>2020-07-29 18:18:40 +0100
commitb9e6c0d3ced0f1d56418b8538c79eede0152171b (patch)
treef537a54dcd7fed87d64672a07a5806a59adf69c8
parent8f22584952c2a3939caf0a69083931fcf3829a54 (diff)
Correct integral image implementation by ensuring that any request for column or row 0 returns 0 for calculations
-rw-r--r--integralimg.go20
1 files changed, 16 insertions, 4 deletions
diff --git a/integralimg.go b/integralimg.go
index 53aec13..922b1ce 100644
--- a/integralimg.go
+++ b/integralimg.go
@@ -142,24 +142,36 @@ func highest(a, b int) int {
func (i Image) topLeft(r image.Rectangle) uint64 {
x := highest(r.Min.X, 0)
y := highest(r.Min.Y, 0)
+ if x == 0 || y == 0 {
+ return 0
+ }
return i[y][x]
}
func (i Image) topRight(r image.Rectangle) uint64 {
- x := lowest(r.Max.X, i.Bounds().Dx() - 1)
+ x := lowest(r.Max.X - 1, i.Bounds().Dx() - 1)
y := highest(r.Min.Y, 0)
+ if x == 0 || y == 0 {
+ return 0
+ }
return i[y][x]
}
func (i Image) bottomLeft(r image.Rectangle) uint64 {
x := highest(r.Min.X, 0)
- y := lowest(r.Max.Y, i.Bounds().Dy() - 1)
+ y := lowest(r.Max.Y - 1, i.Bounds().Dy() - 1)
+ if x == 0 || y == 0 {
+ return 0
+ }
return i[y][x]
}
func (i Image) bottomRight(r image.Rectangle) uint64 {
- x := lowest(r.Max.X, i.Bounds().Dx() - 1)
- y := lowest(r.Max.Y, i.Bounds().Dy() - 1)
+ x := lowest(r.Max.X - 1, i.Bounds().Dx() - 1)
+ y := lowest(r.Max.Y - 1, i.Bounds().Dy() - 1)
+ if x == 0 || y == 0 {
+ return 0
+ }
return i[y][x]
}