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/cmd/wipe/main.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'preproc/cmd/wipe') diff --git a/preproc/cmd/wipe/main.go b/preproc/cmd/wipe/main.go index e735a0a..ceff2e7 100644 --- a/preproc/cmd/wipe/main.go +++ b/preproc/cmd/wipe/main.go @@ -1,7 +1,5 @@ package main -// TODO: add minimum size variable (default ~30%?) - import ( "flag" "fmt" @@ -17,12 +15,13 @@ import ( func main() { flag.Usage = func() { - fmt.Fprintf(os.Stderr, "Usage: wipe [-t thresh] [-w winsize] inimg outimg\n") + fmt.Fprintf(os.Stderr, "Usage: wipe [-m minperc] [-t thresh] [-w winsize] inimg outimg\n") fmt.Fprintf(os.Stderr, "Wipes the sections of an image which are outside the content area.\n") flag.PrintDefaults() } - wsize := flag.Int("w", 5, "Window size for mask finding algorithm.") + min := flag.Int("m", 30, "Minimum percentage of the image width for the content width calculation to be considered valid.") thresh := flag.Float64("t", 0.05, "Threshold for the proportion of black pixels below which a window is determined to be the edge.") + wsize := flag.Int("w", 5, "Window size for mask finding algorithm.") flag.Parse() if flag.NArg() < 2 { flag.Usage() @@ -42,7 +41,7 @@ func main() { gray := image.NewGray(image.Rect(0, 0, b.Dx(), b.Dy())) draw.Draw(gray, b, img, b.Min, draw.Src) - clean := preproc.Wipe(gray, *wsize, *thresh) + clean := preproc.Wipe(gray, *wsize, *thresh, *min) f, err = os.Create(flag.Arg(1)) if err != nil { -- cgit v1.2.1-24-ge1ad