summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.name>2019-07-15 16:10:44 +0100
committerNick White <git@njw.name>2019-07-15 16:10:44 +0100
commite010d0b02bfa6525dc81738f039cb2911b21cec3 (patch)
treed20a847697fb8f70d7b4aa35545691cd42e4b768
parent2d9e3c01298194f248c619f88f018e960768394d (diff)
Add unpaperdir.sh
-rw-r--r--unpaperdir.sh19
1 files changed, 19 insertions, 0 deletions
diff --git a/unpaperdir.sh b/unpaperdir.sh
new file mode 100644
index 0000000..cf518c2
--- /dev/null
+++ b/unpaperdir.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+usage="Usage: $0 directory
+
+Runs unpaper over all *.binarized.png files in a directory,
+saving the result to *.unpapered.png. The output from unpaper
+is also saved, as *.unpaperlog
+"
+
+test $# -ne 1 && echo "$usage" && exit 1
+find "$1" -type f -name '*.binarized.png' | sort | while read i; do
+ d=`dirname "$i"`
+ b=`basename "$i" .binarized.png | sed 's/.jpg.jpg//g'`
+ echo "Unpapering $i to ${b}.unpapered.png"
+
+ rm -f "$d/$b.unpapered.pbm"
+ unpaper --verbose --no-blackfilter --no-noisefilter --no-blurfilter --no-grayfilter --no-border-scan --no-mask-center --no-deskew --mask-scan-size 10,10 --mask-scan-step 2,2 --mask-scan-threshold 0.2 "$i" "$d/${b}.unpapered.pbm" > "$d/${b}.unpaperlog" 2>&1 || exit 1
+ convert "$d/$b.unpapered.pbm" "$d/$b.unpapered.png"
+ rm -f "$d/$b.unpapered.pbm"
+done