sane scanner

From Noah.org
Revision as of 08:35, 12 December 2012 by Root (Talk | contribs) (Scan script)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


The `scanimage` command-line tool is a bit broken. It does not recognize all of the options that it claims in its help page. For example scanimage --help gives an error about an unrecognized option, and then it prints help where --help is clearly listed as an option. Each scanner has options that are specific to it (or the SANE driver that talks to it). You can liste the device specific options simply by having scanimage display help. The scanner must be turned on and connected.

scanimage -h

a simple scan

This will scan the entire scanning surface. The default output format is Net PBM (pnm extension).

scanimage --mode=color --resolution=300 > foo.pnm

TIFF format:

scanimage --format=tiff --mode=color --resolution=300 --depth=14 > foo.tif

autocrop a scan

Often it is simpler to just scan the entire scanning surface and then crop the resulting image, rather than try to figure out the geometry of the scanning surface and tell the scanner which part to scan.

convert foo.pnm -crop `convert foo.pnm -virtual-pixel edge -blur 0x15 -fuzz 15% -trim -format '%[fx:w]x%[fx:h]+%[fx:page.x]+%[fx:page.y]' info:` +repage foo_crop.pnm

scan specified geometry

Scan Polaroid/Fuji instant photos

Scan from the back

This is the natural home cover of the scanner. The scanner scans faster from this corner since it does not have to move the scanning head as far. The down-side is that it's annoying to have to place the photo in this corner because you have to lift the cover more and reach farther back. This might seem trivial, but it gets to be a pain in the ass when you are trying to scan a few dozen photos as fast as you can.

Epson Perfection 1640SU
   back
 ---------
|++HINGE++|
|     ####| <-- instant film picture
|     ####|         108mm X 85mm
|         |
|         |
|         |
|         |
|         |
 ---------
   front

This will scan all of the photo (108mm X 85mm) including the white border. This may be desired if notes are written on the borders.

scanimage --mode=color --resolution=100 --depth=8 -l 0 -x 108 -t 0 -y 85 | display -

This will scan only 100mm X 80mm, thus cropping off a bit of the white border.

scanimage --mode=color --resolution=100 --depth=8 -l 3 -x 100 -t 1 -y 80 | display -

This will scan a standard 4x5 snapshot with a little border for safety.

scanimage --mode=color --resolution=100 --depth=8 -l 0 -x 153 -t 0 -y 103 | display -

Scan from the front

This is a bad position because the scanner usually cannot scan as far to the front as the edge of the glass would make you believe. The problem is that this is often the most convenient spot to put a Polaroid or Fuji instant photo. Fortunately, most of the edge that will be cut-off lies in the white border of the photo. If you nudge the picture just a bit (2 mm) toward the back of the scanner you can be sure none of the photo area inside the border will be cut-off.

It is helpful to glue a ruler at the front edge of the scanner.

Epson Perfection 1640SU
   back
 ---------
|++HINGE++|
|         |
|         |
|         |
|         |
|      ###|
|      ###| <-- instant film picture
|      ###|         85mm X 108mm
 ---------
   front
scanimage --mode=gray --resolution=100 --depth=8 -l 0 -x 85 -t 200 -y 97.18 | display -

Epson Perfection 1640su

This is a decent scanner someone gave me. It is not very fast, but the quality is decent. It is also easy to use from Linux.

Hardware optical resolution is 1600 DPI.

Color bit depth is 14 bits per channel (42 bits per pixel RGB).

Maximum Read Area is 8.5" * 11.7" ( 21.6 cm * 29.7 cm).

Scan script

This is a simple Bash script to help with scanning multiple images.

#!/bin/bash

######################################################################
#
# This is a simple script to scan photos and save them as PNG files.
#
#     Noah Spurrier <noah@noah.org>
#
# LICENSE
#
#     This license is OSI and FSF approved as GPL-compatible.
#     This license identical to the ISC License and is registered with and
#     approved by the Open Source Initiative. For more information vist:
#         http://opensource.org/licenses/isc-license.txt
#
#     Copyright (c) 2012, Noah Spurrier <noah@noah.org>
#
#     Permission to use, copy, modify, and/or distribute this software for any
#     purpose with or without fee is hereby granted, provided that the above
#     copyright notice and this permission notice appear in all copies.
#
#     THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
#     WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
#     MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
#     ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
#     WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
#     ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
#     OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# VERSION
#
#     Version 1
#
######################################################################

readc ()
{
    previous_stty=$(stty -g)
    stty raw -echo
    char=`dd bs=1 count=1 2>/dev/null`
    stty "${previous_stty}"

    if [ -n "$1" ] ; then
        eval $1="${char}"
    else
        REPLY="${char}"
    fi
}

#for ii in $(seq 100); do
#       basename=$(printf "scan-%03d" ${ii})
while true; do
        echo "= Press any key to scan. ="
        readc
        basename=$(date "+scan-%s")
        echo "= Scan to ${basename}.png ="
        scanimage --mode=color --resolution=600 --depth=12 -l 0 -x 106 -t 0 -y 86 > ${basename}.pnm
#        convert ${basename}.pnm -density 600 ${basename}.png
        convert ${basename}.pnm ${basename}.png
        convert ${basename}.pnm -resize 20%  -quality 95 ${basename}.small.jpg
        convert ${basename}.pnm -resize 5% -normalize ${basename}.tn.jpg
        rm ${basename}.pnm
done


#########1#########2#########3#########4#########5#########6#########7
# END
# vim:set sr et ts=4 sw=4 ft=sh: // See Vim, :help 'modeline'