summaryrefslogtreecommitdiff
path: root/unpaperdir.sh
blob: cf518c206c5989b58b00be032876c92801c5e0d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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