summaryrefslogtreecommitdiff
path: root/integralimg
diff options
context:
space:
mode:
authorNick White <git@njw.name>2019-05-13 20:09:09 +0100
committerNick White <git@njw.name>2019-05-13 20:09:09 +0100
commit94dd98e8845ab9b9196c745e2b48b24c2fed162b (patch)
treeb3f5871b7b0f9226cd5a25b5e3ab55744db7ef88 /integralimg
parent6abca706a944a62231608c4a8d8fbdff81f4ca3c (diff)
Use general integralimg functions for wipe functions
Diffstat (limited to 'integralimg')
-rw-r--r--integralimg/integralimg.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/integralimg/integralimg.go b/integralimg/integralimg.go
index 31f3e53..406ed61 100644
--- a/integralimg/integralimg.go
+++ b/integralimg/integralimg.go
@@ -89,7 +89,7 @@ func ToAllIntegralImg(img *image.Gray) WithSq {
}
-// GetWindow gets the values of the corners of a part of an
+// GetWindow gets the values of the corners of a square part of an
// Integral Image, plus the dimensions of the part, which can
// be used to quickly calculate the mean of the area
func (i I) GetWindow(x, y, size int) Window {
@@ -116,6 +116,18 @@ func (i I) GetWindow(x, y, size int) Window {
return Window { i[miny][minx], i[miny][maxx], i[maxy][minx], i[maxy][maxx], maxx-minx, maxy-miny}
}
+// GetVerticalWindow gets the values of the corners of a vertical
+// slice of an Integral Image, starting at x
+func (i I) GetVerticalWindow(x, width int) Window {
+ maxy := len(i) - 1
+ maxx := x + width
+ if maxx > len(i[0])-1 {
+ maxx = len(i[0]) - 1
+ }
+
+ return Window { i[0][x], i[0][maxx], i[maxy][x], i[maxy][maxx], width, maxy }
+}
+
// Sum returns the sum of all pixels in a Window
func (w Window) Sum() uint64 {
return w.bottomright + w.topleft - w.topright - w.bottomleft
@@ -131,6 +143,14 @@ func (w Window) Mean() float64 {
return float64(w.Sum()) / float64(w.Size())
}
+// Proportion returns the proportion of pixels which are on
+func (w Window) Proportion() float64 {
+ area := w.width * w.height
+ // divide by 255 as each on pixel has the value of 255
+ sum := float64(w.Sum()) / 255
+ return float64(area) / sum - 1
+}
+
// MeanWindow calculates the mean value of a section of an Integral
// Image
func (i I) MeanWindow(x, y, size int) float64 {