summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2019-01-30 19:41:48 +0000
committerNick White <git@njw.name>2019-01-30 19:41:48 +0000
commit5a89da512da641732d05d5bb2c49f813672a6990 (patch)
tree43cafad1f6b09c781efb52970696228c05c131eb
parent6bb8ffba746fbcea8a8a359a32afdd591dab0f25 (diff)
Remove dependency on Imger package
-rw-r--r--binarize/main.go35
1 files changed, 25 insertions, 10 deletions
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)
+ }
}