From 778fc08e5d4b58d457e1754325eb0ff4127ccf1d Mon Sep 17 00:00:00 2001 From: Nick White Date: Mon, 13 May 2019 17:41:30 +0100 Subject: Rename cleanup to wipe, and only export main function --- preproc/wipesides.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'preproc/wipesides.go') diff --git a/preproc/wipesides.go b/preproc/wipesides.go index 2afe1d2..60911cd 100644 --- a/preproc/wipesides.go +++ b/preproc/wipesides.go @@ -6,6 +6,8 @@ package preproc import ( "image" "image/color" + + "rescribe.xyz/go.git/binarize" ) type windowslice struct { @@ -69,10 +71,10 @@ func findbestedge(integral [][]uint64, x int, w int) int { return bestx } -// Findedges finds the edges of the main content, by moving a window of wsize +// findedges finds the edges of the main content, by moving a window of wsize // from the middle of the image to the left and right, stopping when it reaches // a point at which there is a lower proportion of black pixels than thresh. -func Findedges(integral [][]uint64, wsize int, thresh float64) (int, int) { +func findedges(integral [][]uint64, wsize int, thresh float64) (int, int) { maxx := len(integral[0]) - 1 var lowedge, highedge int = 0, maxx @@ -93,9 +95,9 @@ func Findedges(integral [][]uint64, wsize int, thresh float64) (int, int) { return lowedge, highedge } -// Wipesides fills the sections of image not within the boundaries +// wipesides fills the sections of image not within the boundaries // of lowedge and highedge with white -func Wipesides(img *image.Gray, lowedge int, highedge int) *image.Gray { +func wipesides(img *image.Gray, lowedge int, highedge int) *image.Gray { b := img.Bounds() new := image.NewGray(b) @@ -120,3 +122,11 @@ func Wipesides(img *image.Gray, lowedge int, highedge int) *image.Gray { return new } + +// wipe fills the sections of image which fall outside the content +// area with white +func Wipe(img *image.Gray, wsize int, thresh float64) *image.Gray { + integral := binarize.Integralimg(img) + lowedge, highedge := findedges(integral, wsize, thresh) + return wipesides(img, lowedge, highedge) +} -- cgit v1.2.1-24-ge1ad