diff options
author | Nick White <git@njw.name> | 2019-04-18 15:52:44 +0100 |
---|---|---|
committer | Nick White <git@njw.name> | 2019-04-18 15:52:44 +0100 |
commit | d270536e034d9f218c4e80792abae389028a918a (patch) | |
tree | f368e927bbf5c58514bf322f3c83a9f418d651a7 /cleanup/main.go | |
parent | 4eb86764539a99b0d7c843d4aa81bfb2955db13c (diff) |
Put edge in middle of window slice, rather than at left side, and gofmt
Diffstat (limited to 'cleanup/main.go')
-rw-r--r-- | cleanup/main.go | 26 |
1 files 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 } } |