From 5a89da512da641732d05d5bb2c49f813672a6990 Mon Sep 17 00:00:00 2001 From: Nick White Date: Wed, 30 Jan 2019 19:41:48 +0000 Subject: Remove dependency on Imger package --- binarize/main.go | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'binarize') diff --git a/binarize/main.go b/binarize/main.go index 610effc..aa8d4ee 100644 --- a/binarize/main.go +++ b/binarize/main.go @@ -6,10 +6,12 @@ package main import ( "flag" "fmt" + "image" + "image/draw" + _ "image/jpeg" + "image/png" "log" "os" - - "github.com/Ernyoke/Imger/imgio" // TODO: get rid of this and do things myself ) func main() { @@ -29,16 +31,29 @@ func main() { *wsize++ } - img, err := imgio.ImreadGray(flag.Arg(0)) + f, err := os.Open(flag.Arg(0)) + defer f.Close() if err != nil { - log.Fatalf("Could not read image %s\n", flag.Arg(0)) + log.Fatalf("Could not open file %s: %v\n", flag.Arg(0), err) } - - // TODO: estimate an appropriate window size based on resolution - thresh := IntegralSauvola(img, *ksize, *wsize) - - err = imgio.Imwrite(thresh, flag.Arg(1)) + img, _, err := image.Decode(f) if err != nil { - log.Fatalf("Could not write image %s\n", flag.Arg(1)) + log.Fatalf("Could not decode image: %v\n", err) } + b := img.Bounds() + gray := image.NewGray(image.Rect(0, 0, b.Dx(), b.Dy())) + draw.Draw(gray, b, img, b.Min, draw.Src) + + // TODO: estimate an appropriate window size based on resolution + thresh := IntegralSauvola(gray, *ksize, *wsize) + + f, err = os.Create(flag.Arg(1)) + if err != nil { + log.Fatalf("Could not create file %s: %v\n", flag.Arg(1), err) + } + defer f.Close() + err = png.Encode(f, thresh) + if err != nil { + log.Fatalf("Could not encode image: %v\n", err) + } } -- cgit v1.2.1-24-ge1ad