From 8af4c7e56e0336f1e70a0e079c79ee7459d92519 Mon Sep 17 00:00:00 2001 From: Nick White Date: Tue, 26 Mar 2019 17:23:33 +0000 Subject: Add zeroinv option for binarize command --- binarize/cmd/binarize/main.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'binarize/cmd') 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 { -- cgit v1.2.1-24-ge1ad