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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#!/bin/bash
. $(which grunch-munch)
limit=250
leftrotation=200
rightrotation=-200
rotmatch $1 $(hundredths $leftrotation) $2
lefterror=$mindiff
rotmatch $1 $(hundredths $rightrotation) $2
righterror=$mindiff
iterlimit=12
while [ $iterlimit -gt 0 ] ; do
iterlimit=$[iterlimit-1]
adjust=$[(leftrotation-rightrotation)/4]
if [ $lefterror -gt $righterror ] ; then
echo "** Adjusting left limit **"
leftrotation=$[leftrotation-adjust]
rotmatch $1 $(hundredths $leftrotation) $2
lefterror=$mindiff
else
echo "** Adjusting right limit **"
rightrotation=$[rightrotation+adjust]
rotmatch $1 $(hundredths $rightrotation) $2
righterror=$mindiff
fi
done
center=$[(leftrotation+rightrotation)/2]
echo "** Take center of remaining angle **"
rotmatch $1 $(hundredths $center) $2
echo ""
echo "** Ended with error $mindiff at rotation of $(hundredths $center) degrees **"
echo ""
echo ""
echo "** Performing brightness-match optimization **"
echo ""
brightmatch $tmp/strip.ppm $tmp/best.ppm
echo ""
echo "** Creating corrected right-side image **"
echo ""
ppmbrighten -v $(hundredths $brighter) < $tmp/rotated.ppm > $tmp/corrected.ppm
echo ""
echo "** Splicing images **"
echo ""
splice $1-1 $tmp/corrected.ppm
mv $tmp/final.tif $1-autojoin.tif
|