Control Scanners in Linux With the SANE API

Scanner Access Now Easy (SANE) is an API for scanning devices including flatbed scanners, video cameras, and stills cameras.

SANE can be installed via your command line package management system either as a stand alone library or as part of one of the front ends.

Why Is SANE an Application Programming Interface (API)?

Well, because it is actually more useful to develop a good API than a bespoke Graphical User Interface (GUI) with a dedicated internal API. GUIs become obsolete quickly in the Linux world.

As soon as someone develops a better front end, they just need to connect it to the API and then you have a new application with a better user interface. It can present the same functionality as the mature API, depending on what is made available. And interfaces do differ considerably.

SANE Front Ends

Because SANE is merely an API, there are multiple ways of accessing its capabilities. The most popular and well know Linux front end is XSANE, which is pictured in the featured image showing a preview scan of a photo with a tiger. Another similar GUI front end is skanlite.

When you install SANE, it comes with a command line front end as well. There are many options to select the device, scanner options, and output file format. For example, this line

scanimage --device "epson2:libusb:002:003" --mode Color --format=png --output-file tiger.png --progress

produces a PNG image of the scanned photograph. If the scanner is network equipped, such as an all-in-one fax/copier/scanner – the device may be accessed by its IP address:

scanimage --device "epson2:net:192.168.1.26" --mode color --format=png --output-file tiger.png --progress

Using Scanners With SANE

Scanners are used for many types of flat media, as well as objects that can present a fairly flat surface to the platen. Your fax machine is a type of scanner and newer ones integrate the functionality of the internal scanner with the fax function.

Dedicated flatbed scanners have additional hardware, such as back lamps for illuminating transparent media and special holders for small media such as film negatives.

Related: The Best Photo Scanners for Backing Up Old Photos

A quick review of the operating systems supported by the scanners will show that the dominant mass-market OSs – Windows and Mac OS are targeted by their proprietary scanning software. However, there are over 1,600 scanners supported, so it probably wouldn’t be too hard to find one that works with SANE that meets your needs and budget.

Scanning Documents

SANE can control the digitization process when scanning documents such as old newspapers, blueprints or drawings. The wide variety of options allows you to alter the resolution, as well as choose color, grayscale or line art.

If you install the utility G Optical Character Recognition (gocr) you can then convert images of printed material to text either through a SANE front end such as XSANE or on the command line after saving the image:

gocr -i  -o output.txt

Note that if you want to try this, some experimentation is required. Media like newspaper articles in multiple columns will require trial and error with the options of gocr in order to produce a readable text file. But, hey, it’s free and it runs in Linux.

Taking Advantage of Printed Photo Conversion

Being the over-scheduled and time deprived people that we are, we use our mobile phones to quickly take a photo of printed media when we need to refer to it again. However, unless we have ourselves a flat photography setup with controllable lighting, camera stand, lenses, etc., we are less likely to get a high quality picture compared to using a scanner.

That’s the most useful application of a scanner, which is essentially taking a high-quality, high resolution photo of a photo. You can control both the resolution and format of the image, whereas with a mobile camera you can control the resolution but not always the format.

Formats can be lossy or lossless, and you want lossless to start out so you have the option to convert down. For example, comparing images from two devices at their highest available resolution:

Device Resolution Size (MB) Format
Pixel4a 4032×3024 13 RAW
Epson WF-3640 6784×4661 94.8 tiff

Note that taking a picture of a picture is not the same as taking a picture of the original scene, so in terms of using RAW format available in some mobile cameras, it is not exactly a fair comparison when converting a printed photograph.

In addition to resolution, the scanner allows you to adjust the gamma as the image is digitized. Gamma is a way of making the shadows darker and light areas lighter, but is not the same as the lightness/darkness adjustment on your mobile camera.

Depending on the scanner, the option to limit the scan to a smaller area of the photo is useful when you need to capture less of the image and want to keep the file size smaller.

Finally, with SANE, you have the ability to change the output format of the image to PNM, TIFF, PNG, or JPEG.

Scanning Photographic Negatives and Slides

If you have developed negatives or slides, these can be scanned and converted to reverse color, effectively (but not quite) reproducing the essential steps of a dark room. You will need a scanner that has a back lamp to support scanning transparent media.

Related: Scan Photographic Slides With This Hack

Add a photo printer and photo paper to this combination and you will enable yourself to print your own photographs from negatives or slides.

Scanning Flat Objects

Why scan an object when you can take a picture? Good question. The reason is that when you take a picture of an object with a handheld camera you can end up with a blurred image either due to the camera not focusing exactly right or movement.

This is good for nature studies of rock, leaves, insect wings, etc. when you don’t have a macro setup for your camera with lighting and glass plates for holding things.

SANE Supported Cameras

SANE supports a limited number of still and video cameras, but until support becomes more widespread or the industry adopts the API widely, connecting your camera via USB will only be good for transferring files.

Are You SANE Yet?

SANE offers Linux users the ability to control many different scanners from the same API, and has many front-end options to access its functionality. You can choose XSANE, Skanlite, or from over a dozen others, depending on your system and particular preferences.

With this tool and an array of other Linux utilities, you can restore old photos, digitize negatives, slides, newspapers and other printed documents. You can even capture minute details in objects not clearly visible with the naked eye or easily photographed.

Source: makeuseof.com

Related posts

The 5 Biggest Features and Changes in Apple’s OLED iPad Pros

Switch 2: 5 Things Id Like to See More Than Just Power

Switch 2: 5 Things Id Like to See More Than Just Power