From 014af190c64b2fecbf5d69e9a13e45858e830e81 Mon Sep 17 00:00:00 2001 From: Nick White Date: Tue, 14 Apr 2020 11:37:57 +0100 Subject: Improve documentation throughout --- cmd/binarize/main.go | 1 + cmd/preproc/main.go | 1 + cmd/preprocmulti/main.go | 2 ++ cmd/splittable/main.go | 2 ++ cmd/wipe/main.go | 2 ++ doc.go | 9 +++++++++ preprocmulti.go | 12 +++++------- sauvola.go | 2 +- util.go | 6 +++--- 9 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 doc.go diff --git a/cmd/binarize/main.go b/cmd/binarize/main.go index a844982..c7cadb2 100644 --- a/cmd/binarize/main.go +++ b/cmd/binarize/main.go @@ -2,6 +2,7 @@ // Use of this source code is governed by the GPLv3 // license that can be found in the LICENSE file. +// binarize does fast Integral Image sauvola binarisation on an image package main import ( diff --git a/cmd/preproc/main.go b/cmd/preproc/main.go index 3323635..e967cd2 100644 --- a/cmd/preproc/main.go +++ b/cmd/preproc/main.go @@ -2,6 +2,7 @@ // Use of this source code is governed by the GPLv3 // license that can be found in the LICENSE file. +// preproc runs binarisation and wipe preprocessing on an image package main // TODO: come up with a way to set a good ksize automatically diff --git a/cmd/preprocmulti/main.go b/cmd/preprocmulti/main.go index ca7799f..911c791 100644 --- a/cmd/preprocmulti/main.go +++ b/cmd/preprocmulti/main.go @@ -2,6 +2,8 @@ // Use of this source code is governed by the GPLv3 // license that can be found in the LICENSE file. +// preprocmulti runs binarisation with a variety of different binarisation +// levels, preprocessing and saving each version package main // TODO: come up with a way to set a good ksize automatically diff --git a/cmd/splittable/main.go b/cmd/splittable/main.go index 9055cf8..ff5082b 100644 --- a/cmd/splittable/main.go +++ b/cmd/splittable/main.go @@ -2,6 +2,8 @@ // Use of this source code is governed by the GPLv3 // license that can be found in the LICENSE file. +// splittable is an experimental program to split a table into +// individual cells suitable for OCR package main import ( diff --git a/cmd/wipe/main.go b/cmd/wipe/main.go index beeced2..30b0061 100644 --- a/cmd/wipe/main.go +++ b/cmd/wipe/main.go @@ -2,6 +2,8 @@ // Use of this source code is governed by the GPLv3 // license that can be found in the LICENSE file. +// wipe wipes sections of an image which are outside of an automatically +// determined content area package main import ( diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..0fffdd9 --- /dev/null +++ b/doc.go @@ -0,0 +1,9 @@ +// Copyright 2020 Nick White. +// Use of this source code is governed by the GPLv3 +// license that can be found in the LICENSE file. + +// preproc contains various image processing methods which are useful +// for preprocessing page images for OCR. It contains both library +// functions to incorporate into your own projects and standalone +// tools which can be used directly. +package preproc diff --git a/preprocmulti.go b/preprocmulti.go index 427ffe7..e671108 100644 --- a/preprocmulti.go +++ b/preprocmulti.go @@ -4,8 +4,6 @@ package preproc -// TODO: come up with a way to set a good ksize automatically - import ( "fmt" "image" @@ -18,8 +16,8 @@ import ( "rescribe.xyz/integralimg" ) -// TODO: do more testing to see how good this assumption is func autowsize(bounds image.Rectangle) int { + // TODO: do more testing to see how good this assumption is return bounds.Dx() / 60 } @@ -31,11 +29,11 @@ func autowsize(bounds image.Rectangle) int { // wipe: Whether to wipe (clear sides) the image // wipeWsize: Window size for wiping algorithm // wipeMinWidthPerc: Minimum percentage of the image width for the content width calculation to be considered valid -// Note: copied from cmd/preprocmulti/main.go, should think about the best way -// to organise this code later. -// TODO: return errors that encapsulate the err describing where it was encountered -// TODO: do the post-integral image stuff in separate goroutines for speed func PreProcMulti(inPath string, ksizes []float64, binType string, binWsize int, wipe bool, wipeWsize int, wipeMinWidthPerc int) ([]string, error) { + // Note: copied from cmd/preprocmulti/main.go, should think about the best way to organise this code later. + // TODO: return errors that encapsulate the err describing where it was encountered + // TODO: come up with a way to set a good ksize automatically + // Make outBase inPath up to final . s := strings.Split(inPath, ".") outBase := strings.Join(s[:len(s)-1], "") diff --git a/sauvola.go b/sauvola.go index c512098..bea78ce 100644 --- a/sauvola.go +++ b/sauvola.go @@ -59,8 +59,8 @@ func IntegralSauvola(img *image.Gray, ksize float64, windowsize int) *image.Gray } // 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 { + // TODO: have this be the root function that the other two reference b := img.Bounds() new := image.NewGray(b) diff --git a/util.go b/util.go index 3ce4f84..f0864e9 100644 --- a/util.go +++ b/util.go @@ -10,10 +10,10 @@ import ( "math" ) -// TODO: name better; maybe verb, x-er -// TODO: implement these for regular image, and use them to make -// image functions generic for integral and non- images type UsefulImg interface { + // TODO: name better; maybe verb, x-er + // TODO: implement these for regular image, and use them to make + // image functions generic for integral and non- images MeanWindow() MeanStdDevWindow() } -- cgit v1.2.1-24-ge1ad