From 26a61941cf0216202aee3378f17b05255170da17 Mon Sep 17 00:00:00 2001 From: Nick White Date: Tue, 29 Jan 2019 13:33:50 +0000 Subject: Switch binarization to Sauvola algorithm --- binarize/binarize.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'binarize/binarize.go') diff --git a/binarize/binarize.go b/binarize/binarize.go index f95ee22..fa8a30f 100644 --- a/binarize/binarize.go +++ b/binarize/binarize.go @@ -7,14 +7,15 @@ import ( "os" "github.com/Ernyoke/Imger/imgio" - "github.com/Ernyoke/Imger/threshold" ) func main() { flag.Usage = func() { - fmt.Fprintf(os.Stderr, "Usage: binarize inimg outimg\n") + fmt.Fprintf(os.Stderr, "Usage: binarize [-w num] [-k num] inimg outimg\n") flag.PrintDefaults() } + wsize := flag.Int("w", 31, "Window size for sauvola algorithm") + ksize := flag.Float64("k", 0.5, "K for sauvola algorithm") flag.Parse() if flag.NArg() < 2 { flag.Usage() @@ -26,7 +27,8 @@ func main() { log.Fatalf("Could not read image %s\n", flag.Arg(0)) } - thresh, err := threshold.OtsuThreshold(img, threshold.ThreshBinary) + // TODO: should be able to estimate an appropriate window size based on resolution + thresh := Sauvola(img, *ksize, *wsize) if err != nil { log.Fatal("Error binarising image\n") } -- cgit v1.2.1-24-ge1ad