From d270536e034d9f218c4e80792abae389028a918a Mon Sep 17 00:00:00 2001 From: Nick White Date: Thu, 18 Apr 2019 15:52:44 +0100 Subject: Put edge in middle of window slice, rather than at left side, and gofmt --- cleanup/main.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cleanup/main.go b/cleanup/main.go index 05ff5f2..26655c7 100644 --- a/cleanup/main.go +++ b/cleanup/main.go @@ -15,20 +15,20 @@ import ( ) type windowslice struct { - topleft uint64 - topright uint64 - bottomleft uint64 + topleft uint64 + topright uint64 + bottomleft uint64 bottomright uint64 } func getwindowslice(i [][]uint64, x int, size int) windowslice { - maxy := len(i)-1 - maxx := x+size + maxy := len(i) - 1 + maxx := x + size if maxx > len(i[0])-1 { - maxx = len(i[0])-1 + maxx = len(i[0]) - 1 } - return windowslice { i[0][x], i[0][maxx], i[maxy][x], i[maxy][maxx] } + return windowslice{i[0][x], i[0][maxx], i[maxy][x], i[maxy][maxx]} } // checkwindow checks the window from x to see whether more than @@ -39,12 +39,12 @@ func checkwindow(integral [][]uint64, x int, size int, thresh float64) bool { // divide by 255 as each on pixel has the value of 255 sum := (window.bottomright + window.topleft - window.topright - window.bottomleft) / 255 area := size * height - proportion := float64(float64(area) / float64(sum)) - 1 + proportion := float64(float64(area)/float64(sum)) - 1 return proportion <= thresh } // cleanimg fills the sections of image not within the boundaries -// of lowedge and highedge with white +// of lowedge and highedge with white func cleanimg(img *image.Gray, lowedge int, highedge int) *image.Gray { b := img.Bounds() new := image.NewGray(b) @@ -98,19 +98,19 @@ func main() { draw.Draw(gray, b, img, b.Min, draw.Src) integral := binarize.Integralimg(gray) - maxx := len(integral[0])-1 + maxx := len(integral[0]) - 1 var lowedge, highedge int = 0, maxx // find right edge - for x := maxx / 2; x < maxx - *wsize; x++ { + for x := maxx / 2; x < maxx-*wsize; x++ { if checkwindow(integral, x, *wsize, *thresh) { - highedge = x + highedge = x + (*wsize / 2) break } } // find left edge for x := maxx / 2; x > 0; x-- { if checkwindow(integral, x, *wsize, *thresh) { - lowedge = x + lowedge = x - (*wsize / 2) break } } -- cgit v1.2.1-24-ge1ad