summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2020-08-04 16:19:01 +0100
committerNick White <git@njw.name>2020-08-04 16:19:01 +0100
commitaa5bd02bd5ed5a6a8d371f953ef128fce64e61a7 (patch)
treee6512607ffc22727ea6cd3cb25bc7db9a4054976
parentb26cb9182b566acac884627d790b0660c4766b62 (diff)
Update to replace integralimg package with integral package
-rw-r--r--cmd/pggraph/main.go4
-rw-r--r--cmd/preprocmulti/main.go6
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--preprocmulti.go6
-rw-r--r--sauvola.go12
-rw-r--r--sauvola_test.go6
-rw-r--r--testdata/pg2_integralwipesides_t0.05_w5.pngbin21735 -> 21738 bytes
-rw-r--r--wipesides.go6
-rw-r--r--wipesides_test.go6
10 files changed, 26 insertions, 26 deletions
diff --git a/cmd/pggraph/main.go b/cmd/pggraph/main.go
index c7909b5..2da5c57 100644
--- a/cmd/pggraph/main.go
+++ b/cmd/pggraph/main.go
@@ -21,7 +21,7 @@ import (
"sort"
chart "github.com/wcharczuk/go-chart"
- "rescribe.xyz/integralimg"
+ "rescribe.xyz/integral"
"rescribe.xyz/preproc"
)
@@ -173,7 +173,7 @@ func main() {
img = sideways(gray)
b = img.Bounds()
}
- intImg := integralimg.NewImage(b)
+ intImg := integral.NewImage(b)
draw.Draw(intImg, b, img, b.Min, draw.Src)
points := make(map[int]float64)
diff --git a/cmd/preprocmulti/main.go b/cmd/preprocmulti/main.go
index b99909a..f5612cf 100644
--- a/cmd/preprocmulti/main.go
+++ b/cmd/preprocmulti/main.go
@@ -19,7 +19,7 @@ import (
"os"
"rescribe.xyz/preproc"
- "rescribe.xyz/integralimg"
+ "rescribe.xyz/integral"
)
// TODO: do more testing to see how good this assumption is
@@ -70,9 +70,9 @@ func main() {
var clean, threshimg image.Image
log.Print("Precalculating integral images")
- intImg := integralimg.NewImage(b)
+ intImg := integral.NewImage(b)
draw.Draw(intImg, b, img, b.Min, draw.Src)
- intSqImg := integralimg.NewSqImage(b)
+ intSqImg := integral.NewSqImage(b)
draw.Draw(intSqImg, b, img, b.Min, draw.Src)
for _, k := range ksizes {
diff --git a/go.mod b/go.mod
index 5c831a9..0a31aad 100644
--- a/go.mod
+++ b/go.mod
@@ -7,5 +7,5 @@ require (
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/wcharczuk/go-chart v2.0.2-0.20191206192251-962b9abdec2b+incompatible
golang.org/x/image v0.0.0-20200618115811-c13761719519 // indirect
- rescribe.xyz/integralimg v0.4.0
+ rescribe.xyz/integral v0.6.0
)
diff --git a/go.sum b/go.sum
index 1b9ac96..dae16b3 100644
--- a/go.sum
+++ b/go.sum
@@ -16,5 +16,5 @@ golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20181205014116-22934f0fdb62/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
-rescribe.xyz/integralimg v0.4.0 h1:KHBskl7xpAc3tKp5Zjm9SWMykUlOqUU5ZOr+eEKWMcI=
-rescribe.xyz/integralimg v0.4.0/go.mod h1:mZKOwJ5vJgV+8yFKuJsWZBqF5AdYZSry6wSuWNsQPQM=
+rescribe.xyz/integral v0.6.0 h1:CLF3sQ6th/OuG+/rp/lLR+AGOT4R7tG3IiUjSLKsriw=
+rescribe.xyz/integral v0.6.0/go.mod h1:gKJq4UaVn17RsMsUasEMcJDkTkwqeb6AzPIJtwcUipg=
diff --git a/preprocmulti.go b/preprocmulti.go
index 25d35ea..187206e 100644
--- a/preprocmulti.go
+++ b/preprocmulti.go
@@ -13,7 +13,7 @@ import (
"os"
"strings"
- "rescribe.xyz/integralimg"
+ "rescribe.xyz/integral"
)
func autowsize(bounds image.Rectangle) int {
@@ -59,9 +59,9 @@ func PreProcMulti(inPath string, ksizes []float64, binType string, binWsize int,
binWsize++
}
- intImg := integralimg.NewImage(b)
+ intImg := integral.NewImage(b)
draw.Draw(intImg, b, img, b.Min, draw.Src)
- intSqImg := integralimg.NewSqImage(b)
+ intSqImg := integral.NewSqImage(b)
draw.Draw(intSqImg, b, img, b.Min, draw.Src)
var clean, threshimg image.Image
diff --git a/sauvola.go b/sauvola.go
index 49181de..75d558c 100644
--- a/sauvola.go
+++ b/sauvola.go
@@ -10,7 +10,7 @@ import (
"image/draw"
"math"
- "rescribe.xyz/integralimg"
+ "rescribe.xyz/integral"
)
// Implements Sauvola's algorithm for text binarization, see paper
@@ -44,16 +44,16 @@ func Sauvola(img image.Image, ksize float64, windowsize int) *image.Gray {
func IntegralSauvola(img image.Image, ksize float64, windowsize int) *image.Gray {
b := img.Bounds()
- intImg := integralimg.NewImage(b)
+ intImg := integral.NewImage(b)
draw.Draw(intImg, b, img, b.Min, draw.Src)
- intSqImg := integralimg.NewSqImage(b)
+ intSqImg := integral.NewSqImage(b)
draw.Draw(intSqImg, b, img, b.Min, draw.Src)
return PreCalcedSauvola(*intImg, *intSqImg, img, ksize, windowsize)
}
// PreCalcedSauvola Implements Sauvola's algorithm using precalculated Integral Images
-func PreCalcedSauvola(intImg integralimg.Image, intSqImg integralimg.SqImage, img image.Image, ksize float64, windowsize int) *image.Gray {
+func PreCalcedSauvola(intImg integral.Image, intSqImg integral.SqImage, img image.Image, ksize float64, windowsize int) *image.Gray {
b := img.Bounds()
gray := image.NewGray(b)
draw.Draw(gray, b, img, b.Min, draw.Src)
@@ -62,8 +62,8 @@ func PreCalcedSauvola(intImg integralimg.Image, intSqImg integralimg.SqImage, im
for y := b.Min.Y; y < b.Max.Y; y++ {
for x := b.Min.X; x < b.Max.X; x++ {
r := centeredRectangle(x, y, windowsize)
- m, dev := integralimg.MeanStdDev(intImg, intSqImg, r)
- // Divide by 255 to adjust from Gray16 used by integralimg to 8 bit Gray
+ m, dev := integral.MeanStdDev(intImg, intSqImg, r)
+ // Divide by 255 to adjust from Gray16 used by integral.Image to 8 bit Gray
m8 := m / 255
dev8 := dev / 255
threshold := m8 * (1 + ksize*((dev8/128)-1))
diff --git a/sauvola_test.go b/sauvola_test.go
index fd5da60..b1e0fff 100644
--- a/sauvola_test.go
+++ b/sauvola_test.go
@@ -20,9 +20,9 @@ func TestBinarization(t *testing.T) {
ksize float64
wsize int
}{
- {"integralsauvola", "testdata/pg1.png", "testdata/pg1_integralsauvola_k0.5_w41.png", 0.5, 41},
- {"integralsauvola", "testdata/pg1.png", "testdata/pg1_integralsauvola_k0.5_w19.png", 0.5, 19},
- {"integralsauvola", "testdata/pg1.png", "testdata/pg1_integralsauvola_k0.3_w19.png", 0.3, 19},
+ {"integralsauvola", "testdata/pg1.png", "testdata/pg1_sauvola_k0.5_w41.png", 0.5, 41},
+ {"integralsauvola", "testdata/pg1.png", "testdata/pg1_sauvola_k0.5_w19.png", 0.5, 19},
+ {"integralsauvola", "testdata/pg1.png", "testdata/pg1_sauvola_k0.3_w19.png", 0.3, 19},
{"sauvola", "testdata/pg1.png", "testdata/pg1_sauvola_k0.5_w41.png", 0.5, 41},
{"sauvola", "testdata/pg1.png", "testdata/pg1_sauvola_k0.5_w19.png", 0.5, 19},
{"sauvola", "testdata/pg1.png", "testdata/pg1_sauvola_k0.3_w19.png", 0.3, 19},
diff --git a/testdata/pg2_integralwipesides_t0.05_w5.png b/testdata/pg2_integralwipesides_t0.05_w5.png
index da09eba..a07aad3 100644
--- a/testdata/pg2_integralwipesides_t0.05_w5.png
+++ b/testdata/pg2_integralwipesides_t0.05_w5.png
Binary files differ
diff --git a/wipesides.go b/wipesides.go
index 7480a7f..644bc9c 100644
--- a/wipesides.go
+++ b/wipesides.go
@@ -16,7 +16,7 @@ import (
"image/png"
"os"
- "rescribe.xyz/integralimg"
+ "rescribe.xyz/integral"
)
// ProportionSlice returns the proportion of black pixels in a
@@ -171,7 +171,7 @@ func sideways(img image.Image) *image.Gray {
// area with white, providing the content area is above min %
func Wipe(img *image.Gray, wsize int, thresh float64, min int) *image.Gray {
b := img.Bounds()
- intImg := integralimg.NewImage(b)
+ intImg := integral.NewImage(b)
draw.Draw(intImg, b, img, b.Min, draw.Src)
lowedge, highedge := findedges(*intImg, wsize, thresh)
if toonarrow(img, lowedge, highedge, min) {
@@ -185,7 +185,7 @@ func Wipe(img *image.Gray, wsize int, thresh float64, min int) *image.Gray {
func VWipe(img *image.Gray, wsize int, thresh float64, min int) *image.Gray {
rotimg := sideways(img)
b := rotimg.Bounds()
- intImg := integralimg.NewImage(b)
+ intImg := integral.NewImage(b)
draw.Draw(intImg, b, rotimg, b.Min, draw.Src)
// TODO: test whether there are any places where Outin makes a real difference
lowedge, highedge:= findedgesOutin(*intImg, wsize, thresh)
diff --git a/wipesides_test.go b/wipesides_test.go
index 660cb16..c23a290 100644
--- a/wipesides_test.go
+++ b/wipesides_test.go
@@ -16,7 +16,7 @@ import (
"os"
"testing"
- "rescribe.xyz/integralimg"
+ "rescribe.xyz/integral"
)
func TestWipeSides(t *testing.T) {
@@ -79,7 +79,7 @@ func TestWipeSides(t *testing.T) {
t.Fatalf("Could not open file %s: %v\n", c.filename, err)
}
b := img.Bounds()
- integral := integralimg.NewImage(b)
+ integral := integral.NewImage(b)
draw.Draw(integral, b, img, b.Min, draw.Src)
leftedge, rightedge := findedges(*integral, c.wsize, c.thresh)
if leftedge < c.minleft {
@@ -119,7 +119,7 @@ func TestWipeSides(t *testing.T) {
b := img.Bounds()
rotimg := sideways(img)
b = rotimg.Bounds()
- intImg := integralimg.NewImage(b)
+ intImg := integral.NewImage(b)
draw.Draw(intImg, b, rotimg, b.Min, draw.Src)
topedge, bottomedge := findedges(*intImg, c.wsize, c.thresh)
if topedge < c.mintop {