From 9d7a737f447a6708ebea3cb0e1513b03b2edc82d Mon Sep 17 00:00:00 2001 From: Daniel Axtens Date: Sat, 6 Aug 2011 14:10:11 +0800 Subject: [PATCH] Fix issue where entire physical pages would disappear. --- scan2pages.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scan2pages.sh b/scan2pages.sh index cbfe52f..3013efe 100755 --- a/scan2pages.sh +++ b/scan2pages.sh @@ -156,7 +156,7 @@ for scanpgnum in `$my_seq 1 $pages`; do # ... get crop co-ords. They're off by ~2 as I don't know how to # properly correct for the border. cropcords=$(convert -border 1x1 -bordercolor '#000' -resize 1000% -trim -fuzz 90% -format "%wx%h%O" $outdir/scanpg-mask-${scanpgnum}.png info: || exit 1) - + # ... crop and despeckle? the final pre-prepared image convert $convertflags -crop $cropcords $binscanpg $cleanscanpg || exit 1 fi; @@ -190,13 +190,22 @@ for scanpgnum in `$my_seq 1 $pages`; do convert $convertflags -resize 10% -depth 8 -gamma 0.01 -median 2 $physpg $outdir/physpg-mask-${scanpgnum}-${physpgnum}.png ||exit 1 # Trim #-border 1x1 -bordercolor '#fff' -trim -fuzz 30% - cropcords=$(convert -trim -fuzz 90%\ + # binarise is so effective, try something << 90% + cropcords=$(convert -trim -fuzz 50%\ -resize 1000% -format "%wx%h%O" $outdir/physpg-mask-${scanpgnum}-${physpgnum}.png info: || exit 1) + [[ $verbose ]] && echo Crop co-ords: $cropcords + # ... crop and despeckle? the final pre-prepared image convert $convertflags -crop $cropcords $physpg $cleanphyspg || exit 1 fi; - + + # check it hasn't mostly disappeared, warn viciously if it has! + if [[ $(convert $cleanphyspg -format '%[fx:s.w*s.h>1000]' info:) = "0" ]]; then + echo "Warning: discarding physical pg ${scanpgnum}-${physpgnum}: not enough remains after masking." + continue; + fi; + #detect if the page is 2-up if [[ $logperphys == 2 ]] || ( [[ $logperphys != 1 ]] && $(dirname $0)/detect2pages.sh ${cleanphyspg} ${scanpgnum} ${physpgnum} ); then -- 2.20.1