diff options
Diffstat (limited to 'preproc/cmd')
-rw-r--r-- | preproc/cmd/preproc/main.go | 13 | ||||
-rw-r--r-- | preproc/cmd/preprocmulti/main.go | 13 |
2 files changed, 18 insertions, 8 deletions
diff --git a/preproc/cmd/preproc/main.go b/preproc/cmd/preproc/main.go index d8d5b66..898efb5 100644 --- a/preproc/cmd/preproc/main.go +++ b/preproc/cmd/preproc/main.go @@ -22,7 +22,7 @@ func autowsize(bounds image.Rectangle) int { func main() { flag.Usage = func() { - fmt.Fprintf(os.Stderr, "Usage: preproc [-bt bintype] [-bw winsize] [-k num] [-m minperc] [-wt wipethresh] [-ws wipesize] inimg outimg\n") + fmt.Fprintf(os.Stderr, "Usage: preproc [-bt bintype] [-bw winsize] [-k num] [-m minperc] [-nowipe] [-wt wipethresh] [-ws wipesize] inimg outimg\n") fmt.Fprintf(os.Stderr, "Binarize and preprocess an image\n") flag.PrintDefaults() } @@ -30,6 +30,7 @@ func main() { ksize := flag.Float64("k", 0.5, "K for sauvola binarization algorithm. This controls the overall threshold level. Set it lower for very light text (try 0.1 or 0.2).") btype := flag.String("bt", "binary", "Type of binarization threshold. binary or zeroinv are currently implemented.") min := flag.Int("m", 30, "Minimum percentage of the image width for the content width calculation to be considered valid.") + nowipe := flag.Bool("nowipe", false, "Disable wiping completely.") wipewsize := flag.Int("ws", 5, "Window size for wiping algorithm.") thresh := flag.Float64("wt", 0.05, "Threshold for the wiping algorithm to determine the proportion of black pixels below which a window is determined to be the edge.") flag.Parse() @@ -60,7 +61,7 @@ func main() { } log.Print("Binarising") - var threshimg image.Image + var clean, threshimg image.Image threshimg = preproc.IntegralSauvola(gray, *ksize, *binwsize) if *btype == "zeroinv" { @@ -70,8 +71,12 @@ func main() { } } - log.Print("Wiping sides") - clean := preproc.Wipe(threshimg.(*image.Gray), *wipewsize, *thresh, *min) + if ! *nowipe { + log.Print("Wiping sides") + clean = preproc.Wipe(threshimg.(*image.Gray), *wipewsize, *thresh, *min) + } else { + clean = threshimg + } f, err = os.Create(flag.Arg(1)) if err != nil { diff --git a/preproc/cmd/preprocmulti/main.go b/preproc/cmd/preprocmulti/main.go index 947625e..9c979c3 100644 --- a/preproc/cmd/preprocmulti/main.go +++ b/preproc/cmd/preprocmulti/main.go @@ -25,7 +25,7 @@ func main() { ksizes := []float64{0.2, 0.3, 0.4, 0.5, 0.6} flag.Usage = func() { - fmt.Fprintf(os.Stderr, "Usage: preproc [-bt bintype] [-bw winsize] [-m minperc] [-wt wipethresh] [-ws wipesize] inimg outbase\n") + fmt.Fprintf(os.Stderr, "Usage: preprocmulti [-bt bintype] [-bw winsize] [-m minperc] [-nowipe] [-wt wipethresh] [-ws wipesize] inimg outbase\n") fmt.Fprintf(os.Stderr, "Binarize and preprocess an image, with multiple binarisation levels,\n") fmt.Fprintf(os.Stderr, "saving images to outbase_bin{k}.png.\n") fmt.Fprintf(os.Stderr, "Binarises with these levels for k: %v.\n", ksizes) @@ -34,6 +34,7 @@ func main() { binwsize := flag.Int("bw", 0, "Window size for sauvola binarization algorithm. Set automatically based on resolution if not set.") btype := flag.String("bt", "binary", "Type of binarization threshold. binary or zeroinv are currently implemented.") min := flag.Int("m", 30, "Minimum percentage of the image width for the content width calculation to be considered valid.") + nowipe := flag.Bool("nowipe", false, "Disable wiping completely.") wipewsize := flag.Int("ws", 5, "Window size for wiping algorithm.") thresh := flag.Float64("wt", 0.05, "Threshold for the wiping algorithm to determine the proportion of black pixels below which a window is determined to be the edge.") flag.Parse() @@ -64,7 +65,7 @@ func main() { *binwsize++ } - var threshimg image.Image + var clean, threshimg image.Image log.Print("Precalculating integral images") integrals := integralimg.ToAllIntegralImg(gray) @@ -79,8 +80,12 @@ func main() { } } - log.Print("Wiping sides") - clean := preproc.Wipe(threshimg.(*image.Gray), *wipewsize, *thresh, *min) + if ! *nowipe { + log.Print("Wiping sides") + clean = preproc.Wipe(threshimg.(*image.Gray), *wipewsize, *thresh, *min) + } else { + clean = threshimg + } savefn := fmt.Sprintf("%s_bin%0.1f.png", flag.Arg(1), k) log.Printf("Saving %s\n", savefn) |