diff options
| author | Nick White <git@njw.name> | 2019-03-26 17:23:33 +0000 | 
|---|---|---|
| committer | Nick White <git@njw.name> | 2019-03-26 17:23:33 +0000 | 
| commit | 8af4c7e56e0336f1e70a0e079c79ee7459d92519 (patch) | |
| tree | 4547e6c029a7063c3fddd6349bc4bbb80364fab3 /binarize/cmd | |
| parent | f20982f465ee4735caf5b0ebc3c57af31ee90e75 (diff) | |
Add zeroinv option for binarize command
Diffstat (limited to 'binarize/cmd')
| -rw-r--r-- | binarize/cmd/binarize/main.go | 13 | 
1 files changed, 11 insertions, 2 deletions
| diff --git a/binarize/cmd/binarize/main.go b/binarize/cmd/binarize/main.go index c4b9562..bda3d93 100644 --- a/binarize/cmd/binarize/main.go +++ b/binarize/cmd/binarize/main.go @@ -20,11 +20,12 @@ func autowsize(bounds image.Rectangle) int {  func main() {  	flag.Usage = func() { -		fmt.Fprintf(os.Stderr, "Usage: sauvola [-w num] [-k num] inimg outimg\n") +		fmt.Fprintf(os.Stderr, "Usage: binarize [-k num] [-t type] [-w num] inimg outimg\n")  		flag.PrintDefaults()  	}  	wsize := flag.Int("w", 0, "Window size for sauvola algorithm. Set automatically based on resolution if not set.")  	ksize := flag.Float64("k", 0.5, "K for sauvola algorithm. This controls the overall threshold level. Set it lower for very light text (try 0.1 or 0.2).") +	btype := flag.String("t", "binary", "Type of threshold. binary or zeroinv are currently implemented.")  	flag.Parse()  	if flag.NArg() < 2 {  		flag.Usage() @@ -55,7 +56,15 @@ func main() {  	// TODO: come up with a way to set a good ksize automatically -	thresh := binarize.IntegralSauvola(gray, *ksize, *wsize) +	var thresh image.Image +	thresh = binarize.IntegralSauvola(gray, *ksize, *wsize) + +	if *btype == "zeroinv" { +		thresh, err = binarize.BinToZeroInv(thresh.(*image.Gray), img.(*image.RGBA)) +		if err != nil { +			log.Fatal(err) +		} +	}  	f, err = os.Create(flag.Arg(1))  	if err != nil { | 
