summaryrefslogtreecommitdiff
path: root/preproc/cmd/wipe
diff options
context:
space:
mode:
authorNick White <git@njw.name>2019-06-03 10:54:02 +0100
committerNick White <git@njw.name>2019-06-03 10:54:02 +0100
commit20b694ee8510692804908f51fbbee3c39c859f37 (patch)
tree106a1354022f1f4ad8983799a88a26dd0f665969 /preproc/cmd/wipe
parentd7f07893d08d9c29f46e50c4f779b0e701f411e4 (diff)
Add -m option to wipe to set minimum content area for wipe to proceed
If content is very light or sparse it may be better to not wipe at all than wipe almost all of the content leaving a small strip. This is done now by aborting the wipe if the detected content takes up less than the minimum % of the page (default is 30%).
Diffstat (limited to 'preproc/cmd/wipe')
-rw-r--r--preproc/cmd/wipe/main.go9
1 files changed, 4 insertions, 5 deletions
diff --git a/preproc/cmd/wipe/main.go b/preproc/cmd/wipe/main.go
index e735a0a..ceff2e7 100644
--- a/preproc/cmd/wipe/main.go
+++ b/preproc/cmd/wipe/main.go
@@ -1,7 +1,5 @@
package main
-// TODO: add minimum size variable (default ~30%?)
-
import (
"flag"
"fmt"
@@ -17,12 +15,13 @@ import (
func main() {
flag.Usage = func() {
- fmt.Fprintf(os.Stderr, "Usage: wipe [-t thresh] [-w winsize] inimg outimg\n")
+ fmt.Fprintf(os.Stderr, "Usage: wipe [-m minperc] [-t thresh] [-w winsize] inimg outimg\n")
fmt.Fprintf(os.Stderr, "Wipes the sections of an image which are outside the content area.\n")
flag.PrintDefaults()
}
- wsize := flag.Int("w", 5, "Window size for mask finding algorithm.")
+ min := flag.Int("m", 30, "Minimum percentage of the image width for the content width calculation to be considered valid.")
thresh := flag.Float64("t", 0.05, "Threshold for the proportion of black pixels below which a window is determined to be the edge.")
+ wsize := flag.Int("w", 5, "Window size for mask finding algorithm.")
flag.Parse()
if flag.NArg() < 2 {
flag.Usage()
@@ -42,7 +41,7 @@ func main() {
gray := image.NewGray(image.Rect(0, 0, b.Dx(), b.Dy()))
draw.Draw(gray, b, img, b.Min, draw.Src)
- clean := preproc.Wipe(gray, *wsize, *thresh)
+ clean := preproc.Wipe(gray, *wsize, *thresh, *min)
f, err = os.Create(flag.Arg(1))
if err != nil {