summaryrefslogtreecommitdiff
path: root/preproc/sauvola.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2019-05-14 10:29:29 +0100
committerNick White <git@njw.name>2019-05-14 10:29:29 +0100
commit3b12c59f37f0dc58ad1886052c03f4c81a2a5b78 (patch)
tree284c4a5edc03f932aa096ba84936f210122e1bb1 /preproc/sauvola.go
parent15b05839f91b29319b9d6fd475007ae3ad6224e2 (diff)
Add preprocmulti tool, that outputs multiple binarisation options quickly
Diffstat (limited to 'preproc/sauvola.go')
-rw-r--r--preproc/sauvola.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/preproc/sauvola.go b/preproc/sauvola.go
index e93ea81..2ed9a92 100644
--- a/preproc/sauvola.go
+++ b/preproc/sauvola.go
@@ -53,3 +53,24 @@ func IntegralSauvola(img *image.Gray, ksize float64, windowsize int) *image.Gray
return new
}
+
+// PreCalcedSauvola Implements Sauvola's algorithm using precalculated Integral Images
+// TODO: have this be the root function that the other two reference
+func PreCalcedSauvola(integrals integralimg.WithSq, img *image.Gray, ksize float64, windowsize int) *image.Gray {
+ b := img.Bounds()
+ new := image.NewGray(b)
+
+ for y := b.Min.Y; y < b.Max.Y; y++ {
+ for x := b.Min.X; x < b.Max.X; x++ {
+ m, dev := integrals.MeanStdDevWindow(x, y, windowsize)
+ threshold := m * (1 + ksize * ((dev / 128) - 1))
+ if img.GrayAt(x, y).Y < uint8(threshold) {
+ new.SetGray(x, y, color.Gray{0})
+ } else {
+ new.SetGray(x, y, color.Gray{255})
+ }
+ }
+ }
+
+ return new
+}