summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2020-07-24 18:59:51 +0100
committerNick White <git@njw.name>2020-07-24 18:59:51 +0100
commit797a8dca9408eb58620bc33dde9b5da51bbfee5f (patch)
tree30f164405261c2ef09a896a3dc3d4704e24b0fd1
parent70e3b595b02977e90c533756a8837c019d51d182 (diff)
Update commands to use the updated interfacesv0.2.0
-rw-r--r--cmd/pggraph/main.go14
-rw-r--r--cmd/preprocmulti/main.go9
-rw-r--r--cmd/splittable/main.go13
3 files changed, 20 insertions, 16 deletions
diff --git a/cmd/pggraph/main.go b/cmd/pggraph/main.go
index 12b2f52..6c13fe2 100644
--- a/cmd/pggraph/main.go
+++ b/cmd/pggraph/main.go
@@ -166,17 +166,19 @@ func main() {
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)
if *vertical {
- gray = sideways(gray)
+ gray := image.NewGray(b)
+ draw.Draw(gray, b, img, b.Min, draw.Src)
+ img = sideways(gray)
+ b = img.Bounds()
}
- integral := integralimg.ToIntegralImg(gray)
+ intImg := integralimg.NewImage(b)
+ draw.Draw(intImg, b, img, b.Min, draw.Src)
points := make(map[int]float64)
- maxx := len(integral[0]) - 1
+ maxx := b.Dx() - 1
for x := 0; x+*width < maxx; x += *width {
- w := integral.GetVerticalWindow(x, *width)
+ w := intImg.GetVerticalWindow(x, *width)
points[x] = w.Proportion()
}
diff --git a/cmd/preprocmulti/main.go b/cmd/preprocmulti/main.go
index 911c791..b99909a 100644
--- a/cmd/preprocmulti/main.go
+++ b/cmd/preprocmulti/main.go
@@ -59,8 +59,6 @@ func main() {
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)
if *binwsize == 0 {
*binwsize = autowsize(b)
@@ -72,11 +70,14 @@ func main() {
var clean, threshimg image.Image
log.Print("Precalculating integral images")
- integrals := integralimg.ToAllIntegralImg(gray)
+ intImg := integralimg.NewImage(b)
+ draw.Draw(intImg, b, img, b.Min, draw.Src)
+ intSqImg := integralimg.NewSqImage(b)
+ draw.Draw(intSqImg, b, img, b.Min, draw.Src)
for _, k := range ksizes {
log.Print("Binarising")
- threshimg = preproc.PreCalcedSauvola(integrals, gray, k, *binwsize)
+ threshimg = preproc.PreCalcedSauvola(*intImg, *intSqImg, img, k, *binwsize)
if *btype == "zeroinv" {
threshimg, err = preproc.BinToZeroInv(threshimg.(*image.Gray), img.(*image.RGBA))
diff --git a/cmd/splittable/main.go b/cmd/splittable/main.go
index ff5082b..3fc5ace 100644
--- a/cmd/splittable/main.go
+++ b/cmd/splittable/main.go
@@ -29,14 +29,14 @@ between those lines.
`
// returns the proportion of the given window that is black pixels
-func proportion(i integralimg.I, x int, size int) float64 {
+func proportion(i integralimg.Image, x int, size int) float64 {
w := i.GetVerticalWindow(x, size)
return w.Proportion()
}
// findbestvline goes through every vertical line from x to x+w to
// find the one with the lowest proportion of black pixels.
-func findbestvline(img integralimg.I, x int, w int) int {
+func findbestvline(img integralimg.Image, x int, w int) int {
var bestx int
var best float64
@@ -60,8 +60,8 @@ func findbestvline(img integralimg.I, x int, w int) int {
// for each line. It works by moving a window of wsize across the image,
// marking each place where there is a higher proportion of black pixels
// than thresh.
-func findvlines(img integralimg.I, wsize int, thresh float64) []int {
- maxx := len(img[0]) - 1
+func findvlines(img integralimg.Image, wsize int, thresh float64) []int {
+ maxx := img.Bounds().Dx() - 1
var lines []int
for x := 0; x < maxx-wsize; x+=wsize {
@@ -114,8 +114,9 @@ func main() {
gray := image.NewGray(image.Rect(0, 0, b.Dx(), b.Dy()))
draw.Draw(gray, b, img, b.Min, draw.Src)
- integral := integralimg.ToIntegralImg(gray)
- vlines := findvlines(integral, *wsize, *thresh)
+ integral := integralimg.NewImage(b)
+ draw.Draw(integral, b, gray, b.Min, draw.Src)
+ vlines := findvlines(*integral, *wsize, *thresh)
for i, v := range vlines {
fmt.Printf("line detected at x=%d\n", v)