diff options
author | Nick White <git@njw.name> | 2019-09-27 18:17:48 +0100 |
---|---|---|
committer | Nick White <git@njw.name> | 2019-09-27 18:17:48 +0100 |
commit | 33e538c56f7513f1b98cab16de771a47a0e2a300 (patch) | |
tree | efb88dea35913b32cc8e890595108ef85e71ac27 /preproc/wipesides.go | |
parent | 99f716ceb58b72016a7828d6956a1160e4346737 (diff) |
Improve wiping procedure to work better with 2 column layouts
Diffstat (limited to 'preproc/wipesides.go')
-rw-r--r-- | preproc/wipesides.go | 10 |
1 files 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 |