summaryrefslogtreecommitdiff
path: root/binarize/util.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2019-03-26 17:23:33 +0000
committerNick White <git@njw.name>2019-03-26 17:23:33 +0000
commit8af4c7e56e0336f1e70a0e079c79ee7459d92519 (patch)
tree4547e6c029a7063c3fddd6349bc4bbb80364fab3 /binarize/util.go
parentf20982f465ee4735caf5b0ebc3c57af31ee90e75 (diff)
Add zeroinv option for binarize command
Diffstat (limited to 'binarize/util.go')
-rw-r--r--binarize/util.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/binarize/util.go b/binarize/util.go
index e7fcfe4..ad641c9 100644
--- a/binarize/util.go
+++ b/binarize/util.go
@@ -1,6 +1,7 @@
package binarize
import (
+ "errors"
"image"
"math"
)
@@ -65,3 +66,22 @@ func surrounding(img *image.Gray, x int, y int, size int) []int {
}
return s
}
+
+func BinToZeroInv(bin *image.Gray, orig *image.RGBA) (*image.RGBA, error) {
+ b := bin.Bounds()
+ if ! b.Eq(orig.Bounds()) {
+ return orig, errors.New("bin and orig images need to be the same dimensions")
+ }
+ newimg := image.NewRGBA(image.Rect(0, 0, b.Dx(), b.Dy()))
+ for y := b.Min.Y; y < b.Max.Y; y++ {
+ for x := b.Min.X; x < b.Max.X; x++ {
+ if bin.GrayAt(x, y).Y == 255 {
+ newimg.Set(x, y, bin.GrayAt(x, y))
+ } else {
+ newimg.Set(x, y, orig.At(x, y))
+ }
+ }
+ }
+
+ return newimg, nil
+}