From 33e538c56f7513f1b98cab16de771a47a0e2a300 Mon Sep 17 00:00:00 2001 From: Nick White Date: Fri, 27 Sep 2019 18:17:48 +0100 Subject: Improve wiping procedure to work better with 2 column layouts --- preproc/wipesides.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/preproc/wipesides.go b/preproc/wipesides.go index 9b8387a..24fb7bd 100644 --- a/preproc/wipesides.go +++ b/preproc/wipesides.go @@ -39,20 +39,24 @@ func findbestedge(img integralimg.I, x int, w int) int { } // 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 +// from near 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(img integralimg.I, wsize int, thresh float64) (int, int) { maxx := len(img[0]) - 1 var lowedge, highedge int = 0, maxx - for x := maxx / 2; x < maxx-wsize; x++ { + // don't start at the middle, as this will fail for 2 column layouts, + // start 10% left or right of the middle + notcentre := maxx / 10 + + for x := maxx / 2 + notcentre; x < maxx-wsize; x++ { if proportion(img, x, wsize) <= thresh { highedge = findbestedge(img, x, wsize) break } } - for x := maxx / 2; x > 0; x-- { + for x := maxx / 2 - notcentre; x > 0; x-- { if proportion(img, x, wsize) <= thresh { lowedge = findbestedge(img, x, wsize) break -- cgit v1.2.1-24-ge1ad