diff options
| author | Nick White <git@njw.name> | 2020-07-23 22:57:21 +0100 | 
|---|---|---|
| committer | Nick White <git@njw.name> | 2020-07-23 22:57:21 +0100 | 
| commit | 5ad45af43af2cdc832226632af2024cf416baedd (patch) | |
| tree | 3e79a7fea79adffa166d7a1270f1d6b52eed9cf2 | |
| parent | 6f99873967af11405dbb392346900503617fe48b (diff) | |
Fix bug in Window.Proportion() to tally with Gray16 usage, and use the general image Bounds functions in Window functionsv0.2.1
| -rw-r--r-- | integralimg.go | 18 | 
1 files changed, 10 insertions, 8 deletions
| diff --git a/integralimg.go b/integralimg.go index afdbebe..0ad734b 100644 --- a/integralimg.go +++ b/integralimg.go @@ -130,8 +130,8 @@ func (i Image) GetWindow(x, y, size int) Window {  	step := size / 2  	minx, miny := 0, 0 -	maxy := len(i)-1 -	maxx := len(i[0])-1 +	maxy := i.Bounds().Dy() - 1 +	maxx := i.Bounds().Dx() - 1  	if y > (step+1) {  		miny = y - step - 1 @@ -157,10 +157,11 @@ func (i SqImage) GetWindow(x, y, size int) Window {  // GetVerticalWindow gets the values of the corners of a vertical  // slice of an Integral Image, starting at x  func (i Image) GetVerticalWindow(x, width int) Window { -	maxy := len(i) - 1 +	maxy := i.Bounds().Dy() - 1 +	xbound := i.Bounds().Dx() - 1  	maxx := x + width -	if maxx > len(i[0])-1 { -		maxx = len(i[0]) - 1 +	if maxx > xbound { +		maxx = xbound  	}  	return Window { i[0][x], i[0][maxx], i[maxy][x], i[maxy][maxx], width, maxy } @@ -188,9 +189,10 @@ func (w Window) Mean() float64 {  // 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 +	// 1 << 16 - 1 as we're using Gray16, so for a binarised +	// image then 1 << 16 - 1 = on +	sum := float64(w.Sum()) / float64(1 << 16 - 1) +	return float64(area) / float64(sum) - 1  }  // MeanStdDevWindow calculates the mean and standard deviation of | 
