I am using scanimage
with a document scanner (Canon DR-2510C) that supports duplex scanning. Unfortunately, its SANE driver does not support blank page detection, so that with mixed pages (single/double-sided), blank pages make it into the scan result.
I would like to automatically get rid of those blank pages when post-processing the scan output, so I am looking for a command-line tool that is able to detect whether a TIFF or PNM file consists of mostly white pixels).
Any ideas?
This is the solution I came up with based on the answer by lesmana:
for i in "${DEST_DIR}/out"*.pnm; do
histogram=`convert "${i}" -threshold 50% -format %c histogram:info:-`
white=`echo "${histogram}" | grep "white" | sed -n 's/^ *\(.*\):.*$/\1/p'`
black=`echo "${histogram}" | grep "black" | sed -n 's/^ *\(.*\):.*$/\1/p'`
blank=`echo "scale=4; ${black}/${white} < 0.005" | bc`
if [ ${blank} -eq "1" ]; then
echo "${i} seems to be blank - removing it..."
rm "${i}"
fi
done