From 20b694ee8510692804908f51fbbee3c39c859f37 Mon Sep 17 00:00:00 2001 From: Nick White Date: Mon, 3 Jun 2019 10:54:02 +0100 Subject: Add -m option to wipe to set minimum content area for wipe to proceed If content is very light or sparse it may be better to not wipe at all than wipe almost all of the content leaving a small strip. This is done now by aborting the wipe if the detected content takes up less than the minimum % of the page (default is 30%). --- preproc/wipesides.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'preproc/wipesides.go') diff --git a/preproc/wipesides.go b/preproc/wipesides.go index 04bfa11..9b8387a 100644 --- a/preproc/wipesides.go +++ b/preproc/wipesides.go @@ -90,10 +90,25 @@ func wipesides(img *image.Gray, lowedge int, highedge int) *image.Gray { return new } +// toonarrow checks whether the area between lowedge and highedge is +// less than min % of the total image width +func toonarrow(img *image.Gray, lowedge int, highedge int, min int) bool { + b := img.Bounds() + imgw := b.Max.X - b.Min.X + wipew := highedge - lowedge + if float64(wipew) / float64(imgw) * 100 < float64(min) { + return true + } + return false +} + // 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 { +// area with white, providing the content area is above min % +func Wipe(img *image.Gray, wsize int, thresh float64, min int) *image.Gray { integral := integralimg.ToIntegralImg(img) lowedge, highedge := findedges(integral, wsize, thresh) + if toonarrow(img, lowedge, highedge, min) { + return img + } return wipesides(img, lowedge, highedge) } -- cgit v1.2.1-24-ge1ad