summaryrefslogtreecommitdiff
path: root/binarize/binarize.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2019-01-29 13:33:50 +0000
committerNick White <git@njw.name>2019-01-29 13:33:50 +0000
commit26a61941cf0216202aee3378f17b05255170da17 (patch)
treed2f3b554437d59dea5a6490491638d44dee6c241 /binarize/binarize.go
parent0f145c2315f794210160d2c65874aaf051c5911b (diff)
Switch binarization to Sauvola algorithm
Diffstat (limited to 'binarize/binarize.go')
-rw-r--r--binarize/binarize.go8
1 files changed, 5 insertions, 3 deletions
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")
}