-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_deskew.sh
executable file
·49 lines (39 loc) · 1.26 KB
/
image_deskew.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
scan="$1"
temptif=`mktemp /tmp/temp-XXXXXXXX`
sub_folder=deskew
rm -f $temptif
temptif="$temptif.tif"
if [ -e "${scan}" ]; then
scan_folder=`dirname ${scan}`
pushd ${scan_folder} > /dev/null
scan_folder=`pwd`
popd > /dev/null
if [ ! -d ${scan_folder}/${sub_folder} ]; then
mkdir ${scan_folder}/${sub_folder}
fi
skew_log=${scan_folder}/${sub_folder}/log.txt
scanfile=`basename "${scan}"`
deskewed=0
if [ -f "${skew_log}" ]; then
grep -q "${scanfile}" "${skew_log}" && deskewed=1
fi
# Only de-skew files once.
if [ "${deskewed}" == "0" ]; then
# Find the skew
skew=`nice tiff_findskew $scan`
echo "${scanfile} ${skew}" >> "${skew_log}"
# Now we need to reverse the skew angle
skew=`echo "$skew * -1" | bc`
# Use BC to calculate is skew is outside +/- 0.25 degrees
offenough=`echo "$skew > 0.25 || $skew < -0.25" | bc`
if [ "$offenough" == "1" ] ; then
echo "Deskewing $scan by $skew degrees."
nice tiff2rgba "${scan}" ${temptif}
nice mogrify -adaptive-blur 3x3 -rotate ${skew} -type Bilevel ${temptif}
mv ${temptif} "${scan}"
fi
fi
else
echo "file $scan not found."
fi