summaryrefslogtreecommitdiff
path: root/preprocmulti.go
diff options
context:
space:
mode:
Diffstat (limited to 'preprocmulti.go')
-rw-r--r--preprocmulti.go19
1 files changed, 10 insertions, 9 deletions
diff --git a/preprocmulti.go b/preprocmulti.go
index 187206e..3725471 100644
--- a/preprocmulti.go
+++ b/preprocmulti.go
@@ -29,9 +29,9 @@ func autowsize(bounds image.Rectangle) int {
// wipe: Whether to wipe (clear sides) the image
// wipeWsize: Window size for wiping algorithm
// wipeMinWidthPerc: Minimum percentage of the image width for the content width calculation to be considered valid
-func PreProcMulti(inPath string, ksizes []float64, binType string, binWsize int, wipe bool, wipeWsize int, wipeMinWidthPerc int) ([]string, error) {
- // Note: copied from cmd/preprocmulti/main.go, should think about the best way to organise this code later.
- // TODO: return errors that encapsulate the err describing where it was encountered
+// vWipeWsize: Window size for vertical wiping algorithm
+// wipeMinHeightPerc: Minimum percentage of the image height for the content height calculation to be considered valid
+func PreProcMulti(inPath string, ksizes []float64, binType string, binWsize int, wipe bool, wipeWsize int, wipeMinWidthPerc int, vWipeWsize int, wipeMinHeightPerc int) ([]string, error) {
// TODO: come up with a way to set a good ksize automatically
// Make outBase inPath up to final .
@@ -42,12 +42,12 @@ func PreProcMulti(inPath string, ksizes []float64, binType string, binWsize int,
f, err := os.Open(inPath)
if err != nil {
- return donePaths, err
+ return donePaths, fmt.Errorf("Error opening %s: %v", inPath, err)
}
defer f.Close()
img, _, err := image.Decode(f)
if err != nil {
- return donePaths, err
+ return donePaths, fmt.Errorf("Error decoding image %s: %v", inPath, err)
}
b := img.Bounds()
@@ -72,12 +72,13 @@ func PreProcMulti(inPath string, ksizes []float64, binType string, binWsize int,
if binType == "zeroinv" {
threshimg, err = BinToZeroInv(threshimg.(*image.Gray), img.(*image.RGBA))
if err != nil {
- return donePaths, err
+ return donePaths, fmt.Errorf("Error in BinToZeroInv: ", err)
}
}
if wipe {
- clean = Wipe(threshimg.(*image.Gray), wipeWsize, k*0.02, wipeMinWidthPerc)
+ vclean := VWipe(threshimg.(*image.Gray), vWipeWsize, k*0.02, wipeMinHeightPerc)
+ clean = Wipe(vclean, wipeWsize, k*0.02, wipeMinWidthPerc)
} else {
clean = threshimg
}
@@ -85,12 +86,12 @@ func PreProcMulti(inPath string, ksizes []float64, binType string, binWsize int,
savefn := fmt.Sprintf("%s_bin%0.1f.png", outBase, k)
f, err = os.Create(savefn)
if err != nil {
- return donePaths, err
+ return donePaths, fmt.Errorf("Error creating file %s: %v", savefn, err)
}
defer f.Close()
err = png.Encode(f, clean)
if err != nil {
- return donePaths, err
+ return donePaths, fmt.Errorf("Error encoding image as png: %v", savefn, err)
}
donePaths = append(donePaths, savefn)
}