From: Daniel Axtens Date: Sun, 31 Jul 2011 08:29:03 +0000 (+0800) Subject: Whatever it was I was doing when semester got busy. X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=8f4ebaf877ac3e1113b60cbdad00dbeb3c7bcaf7;p=dja%2Fscandal.git Whatever it was I was doing when semester got busy. --- diff --git a/scan2pages.sh b/scan2pages.sh index 720acec..ccb464b 100755 --- a/scan2pages.sh +++ b/scan2pages.sh @@ -168,29 +168,44 @@ for pg in `$my_seq 1 $pages`; do unpaper $unpaperflags --layout double --overwrite -ni 10 -op 2 $preppnm ${unppnmbase}-%01d.pnm || exit 1 fi; - #detect if the page is 2-up for subpg in $($my_seq 1 2); do echo Processing subpg ${subpg}. - if $(dirname $0)/detect2pages.sh $dir/upg-${pgn}-${subpg}.pnm ${pgn} ${subpg}; then + + subpgfile=${unppnmbase}-${subpg}.pnm #$unppnmbase has $dir/ already + + prepsubpnm=$dir/upg-pp-${pgn}-${subpg}.pnm + + # remask and retrim. FIXME: may throw off 2page detection + convert $convertflags -resize 10% -depth 8 -gamma 0.01 -median 2 $subpgfile $dir/spg-mask-${pgn}-${subpg}.png ||exit 1 + + # Trim #-border 1x1 -bordercolor '#fff' -trim -fuzz 30% + cropcords=$(convert -trim -fuzz 90%\ + -resize 1000% -format "%wx%h%O" $dir/spg-mask-${pgn}-${subpg}.png info: || exit 1) + + # ... crop and despeckle? the final pre-prepared image + convert $convertflags -crop $cropcords $subpgfile $prepsubpnm || exit 1 + + #detect if the page is 2-up + + if $(dirname $0)/detect2pages.sh ${prepsubpnm} ${pgn} ${subpg}; then if [[ $verbose == 1 ]]; then echo "Resplitting subpg ${subpg}." fi - unpaper $unpaperflags --pre-rotate 90 --layout double --overwrite -op 2 $dir/upg-${pgn}-${subpg}.pnm $dir/upg-${pgn}-${subpg}-%01d.pnm + unpaper $unpaperflags --pre-rotate 90 --layout double --overwrite -op 2 $prepsubpnm $dir/upg-${pgn}-${subpg}-%01d.pnm || exit 1 else - cp $dir/upg-${pgn}-${subpg}.pnm $dir/upg-${pgn}-${subpg}-1.pnm + cp $prepsubpnm $dir/upg-${pgn}-${subpg}-1.pnm fi; + + #final convert and clean w/ bebook optimisation + if [[ $bebook ]]; then + convert $convertflags -colorspace Gray -median 1 $dir/upg-${pgn}-${subpg}-?.pnm -trim -fuzz 80% -resize 1200x1600 $dir/final-${pgn}-${subpg}-%01d.${extension} || exit 1 + else + convert $convertflags $dir/upg-${pgn}-${subpg}-?.pnm $dir/final-${pgn}-${subpg}-%01d.${extension} || exit 1 + fi + done; - #final convert and clean w/ bebook optimisation - if [[ $bebook ]]; then - convert $convertflags -colorspace Gray -median 1 $dir/upg-${pgn}-1-?.pnm -trim -resize 1200x1600 $dir/final-${pgn}-1-%01d.${extension} || exit 1 - convert $convertflags -colorspace Gray -median 1 $dir/upg-${pgn}-2-?.pnm -trim -resize 1200x1600 $dir/final-${pgn}-2-%01d.${extension} || exit 1 - else - convert $convertflags $dir/upg-${pgn}-1-?.pnm $dir/final-${pgn}-1-%01d.${extension} || exit 1 - convert $convertflags $dir/upg-${pgn}-2-?.pnm $dir/final-${pgn}-2-%01d.${extension} || exit 1 - fi - done mkdir -p $dir/pages