Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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}"
share|improve this question
up vote 0 down vote accepted

You can use ImageMagick compare tool to compare the scanned images against a "master" blank page. Since my ImageMagick-fu is quite limited I cannot give you any example command. You will have to RTFM:

The second link even has a section titled "Blank Fax" which explains how to detect blank fax pages. Sadly that section seems unfinished. Hopefully the available information is enough for you to get started.

share|improve this answer

Use the identify feature of ImageMagik CLI as given here:

With command:

$ identify -format "%#" source.png

If the number of colors is 1, you have a blank page.

You can also use the command:

identify -verbose source.png

The standard deviation, skew and kurtosis will be 0 for a blank image.

share|improve this answer

My trick is to scan the images to a losslessly compressed format (tiff + compression). This way, blank pages have a much lower file size and I can detect them with find, move them to another directory, check them quickly with a viewer and then get rid of them.

share|improve this answer

Slightly improved version of the code in the question:


mkdir -p "blanks"

for i in "$@"; do
    echo "${i}"
    if [[ -e $(dirname "$i")/.$(basename "$i") ]]; then
        echo "   protected."

    histogram=$(convert "${i}" -threshold 50% -format %c histogram:info:-)
    #echo $histogram
    white=$(echo "${histogram}" | grep "white" | cut -d: -f1)
    black=$(echo "${histogram}" | grep "black" | cut -d: -f1)
    if [[ -z "$black" ]]; then

    blank=$(echo "scale=4; ${black}/${white} < 0.005" | bc)
    #echo $white $black $blank
    if [ "${blank}" -eq "1" ]; then
        echo "${i} seems to be blank - removing it..."
        mv "${i}" "blanks/${i}"


  • Pass the images to check as arguments instead of reading from a fixed location
  • Progress report
  • If the code doesn't detect a file correctly, you can give it a hint (create an empty file with the name of the image plus a dot in front, i.e. to protect a.pnm, use touch .a.pnm)
  • Fixed error when there were no black pixels in the input
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.