From 3b12c59f37f0dc58ad1886052c03f4c81a2a5b78 Mon Sep 17 00:00:00 2001 From: Nick White Date: Tue, 14 May 2019 10:29:29 +0100 Subject: Add preprocmulti tool, that outputs multiple binarisation options quickly --- preproc/sauvola.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'preproc/sauvola.go') 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 +} -- cgit v1.2.1-24-ge1ad