diff options
Diffstat (limited to 'preproc')
-rw-r--r-- | preproc/cmd/wipe/main.go (renamed from preproc/cmd/cleanup/main.go) | 12 | ||||
-rw-r--r-- | preproc/wipesides.go | 18 | ||||
-rw-r--r-- | preproc/wipesides_test.go | 6 |
3 files changed, 18 insertions, 18 deletions
diff --git a/preproc/cmd/cleanup/main.go b/preproc/cmd/wipe/main.go index 7ea0c84..e735a0a 100644 --- a/preproc/cmd/cleanup/main.go +++ b/preproc/cmd/wipe/main.go @@ -1,8 +1,6 @@ package main // TODO: add minimum size variable (default ~30%?) -// TODO: make into a small library -// TODO: have the integral image specific stuff done by interface functions import ( "flag" @@ -14,13 +12,13 @@ import ( "log" "os" - "rescribe.xyz/go.git/binarize" "rescribe.xyz/go.git/preproc" ) func main() { flag.Usage = func() { - fmt.Fprintf(os.Stderr, "Usage: cleanup [-t thresh] [-w winsize] inimg outimg\n") + fmt.Fprintf(os.Stderr, "Usage: wipe [-t thresh] [-w winsize] inimg outimg\n") + fmt.Fprintf(os.Stderr, "Wipes the sections of an image which are outside the content area.\n") flag.PrintDefaults() } wsize := flag.Int("w", 5, "Window size for mask finding algorithm.") @@ -44,11 +42,7 @@ func main() { gray := image.NewGray(image.Rect(0, 0, b.Dx(), b.Dy())) draw.Draw(gray, b, img, b.Min, draw.Src) - integral := binarize.Integralimg(gray) - - lowedge, highedge := preproc.Findedges(integral, *wsize, *thresh) - - clean := preproc.Wipesides(gray, lowedge, highedge) + clean := preproc.Wipe(gray, *wsize, *thresh) f, err = os.Create(flag.Arg(1)) if err != nil { diff --git a/preproc/wipesides.go b/preproc/wipesides.go index 2afe1d2..60911cd 100644 --- a/preproc/wipesides.go +++ b/preproc/wipesides.go @@ -6,6 +6,8 @@ package preproc import ( "image" "image/color" + + "rescribe.xyz/go.git/binarize" ) type windowslice struct { @@ -69,10 +71,10 @@ func findbestedge(integral [][]uint64, x int, w int) int { return bestx } -// Findedges finds the edges of the main content, by moving a window of wsize +// findedges finds the edges of the main content, by moving a window of wsize // from the middle of the image to the left and right, stopping when it reaches // a point at which there is a lower proportion of black pixels than thresh. -func Findedges(integral [][]uint64, wsize int, thresh float64) (int, int) { +func findedges(integral [][]uint64, wsize int, thresh float64) (int, int) { maxx := len(integral[0]) - 1 var lowedge, highedge int = 0, maxx @@ -93,9 +95,9 @@ func Findedges(integral [][]uint64, wsize int, thresh float64) (int, int) { return lowedge, highedge } -// Wipesides fills the sections of image not within the boundaries +// wipesides fills the sections of image not within the boundaries // of lowedge and highedge with white -func Wipesides(img *image.Gray, lowedge int, highedge int) *image.Gray { +func wipesides(img *image.Gray, lowedge int, highedge int) *image.Gray { b := img.Bounds() new := image.NewGray(b) @@ -120,3 +122,11 @@ func Wipesides(img *image.Gray, lowedge int, highedge int) *image.Gray { return new } + +// wipe fills the sections of image which fall outside the content +// area with white +func Wipe(img *image.Gray, wsize int, thresh float64) *image.Gray { + integral := binarize.Integralimg(img) + lowedge, highedge := findedges(integral, wsize, thresh) + return wipesides(img, lowedge, highedge) +} diff --git a/preproc/wipesides_test.go b/preproc/wipesides_test.go index 76151fb..b0ada4e 100644 --- a/preproc/wipesides_test.go +++ b/preproc/wipesides_test.go @@ -11,8 +11,6 @@ import ( "image/png" "os" "testing" - - "rescribe.xyz/go.git/binarize" ) var update = flag.Bool("update", false, "update golden files") @@ -79,9 +77,7 @@ func TestWipeSides(t *testing.T) { if err != nil { t.Fatalf("Could not open file %s: %v\n", c.orig, err) } - integral := binarize.Integralimg(orig) - lowedge, highedge := Findedges(integral, c.wsize, c.thresh) - actual = Wipesides(orig, lowedge, highedge) + actual = Wipe(orig, c.wsize, c.thresh) if *update { f, err := os.Create(c.golden) defer f.Close() |