Fast image processing with ExactImage

Less is More

Article from Issue 176/2015
Author(s):

Automate image processing with this quick and easy-to-use photo tool suite.

Anyone processing images automatically in batch mode needs lean, easy-to-use tools. The program of choice is usually convert from the ImageMagick suite [1]; however, this program has some drawbacks. In particular, convert does not necessarily impress with its stability. This is not typically a major issue, but in case of complex command lines, you might see the program calls abort with a (mostly incomprehensible) error message and produce incorrect results, or even none at all.

In fact, even composing a command line for convert proves to be a task that should not be underestimated: The program supports no fewer than 300 different options that often exhibit strange syntax. Many options serve very specific tasks and require experience and a great deal of background knowledge on the part of the user – for example, do you know offhand what calling convert -resize 200\>x300^ … would give you?

Many users also complain about the lack of effectiveness of the ImageMagick tools. The programs are not especially quick, nor do they deliver particularly brilliant results – in part because of the massive functional diversity, which is often not needed.

The GraphicsMagick [2] suite is an attempt to resolve these issues; another competitor goes by the name of ExactImage [3]. Both provide only a subset of ImageMagick's repertoire and restrict their feature set to the most important functions.

What differences exist between the three suites? Although ImageMagick comes with almost 20 different programs, GraphicsMagick is a single program – along with three configuration tools; ExactImage provides seven tools (Table 1).

Table 1

ExactImage Programs*

Program

Function

bardecode

Reads barcodes

e2mtiff

Groups multiple images as a multipage TIFF

econvert

Universal converter; counterpart to convert from ImageMagick

edentify

Identifies image files; counterpart to identify from ImageMagick

empty-page

Detects images of empty pages

hocr2pdf

Uses hOCR files to generate searchable PDFs

optimize2bw

Optimizes image files for archiving

*Additionally, edisplay is a version of ImageMagick's display program that is no longer supported.

Although GraphicsMagick tries to cover most of ImageMagick's functions, the tiny ExactImage suite delivers only one universal tool (econvert, as a counterpart to convert), as well as some programs for very specific tasks, such as reading barcodes and detecting blank pages.

And, Action!

Like convert from the ImageMagick tools, econvert is the main tool when it comes to creating new images from existing ones. The syntax follows the structure:

$ econvert -i <input file> -<option> ... -o <output file>

The main thing here is to pay attention to the correct order of the individual components; otherwise, econvert (just like convert) might ignore the specified options. Starting with a single input file, you can use multiple switches -<option> -o <output file> to create as many output files as you like on a single command line.

The way the ExactImage tools work is completely controlled by various options, just like ImageMagick (Table 2). ExactImage supports only a subset of the available image formats, and they differ in terms of input and output (Table 3). That said, ExactImage does support the main image formats to a large extent.

Table 2

Important Options

Option

Function

--compress <method>

Compression method for output, say, G3, G4, ZIP, …

--quality <percent>

Defines the quality as a percentage, default: 75

--resolution <xdpi [ydpi]>

Resolution in X and Y direction

--size <width>x<height>

Defines the width and height of the output file for raw image formats

--scale <factor>

Scales by the stated factor

--crop <x y w h>

Crops the image to the specified section

--fast-auto-crop

Automatic cropping (from the bottom edge)

--flip

Mirrors vertically

--flop

Mirrors horizontally

--rotate <angle>

Rotates the image through the stated angle

--brightness <value>

Adjusts the brightness (-1 to +1)

--contrast <value>

Adjusts the contrast (-1 to +1)

--saturation <value>

Adjusts the saturation (-1 to +1)

--lightness <value>

Adjusts the lightness (-1 to +1)

--hue <value>

Adjusts the hue (-360 to +360)

--negate

Creates a negative

--gamma <value>

Adjusts the gamma

--normalize

"Normalizes" the colors in the image

--colorspace <model>

Converts images to one of the color models BW, BILEVEL, GRAY, GRAY1, GRAY2, GRAY4, RGB, YUV, or CMYK

--floyd-steinberg <value>

Generates shade as per Floyd-Steinberg

--riemersma <value>

Generates shade as per Riemersma

--blur <value>

Gaussian blur

--edge

Finds edges

--foreground <color>

Sets the drawing color

--background <color>

Sets the background color

--font <Font>

Sets the font

--text <x1 y1 text size>

Outputs the text at the specified position at the specified size

--text-rotation <angle>

Rotates texts

--stroke-width <thickness>

Line thickness

--line <x1 y1 x2 y2>

Draw line between specified points

Table 3

Image Formats

Abbreviation

Image Format

BMP

Windows primitive bitmap format

Digital Camera RAW

Raw data formats supported by DCRAW

Encapsulated PostScript

Single-sided PostScript

GIF

The legacy bitmap format

JPEG

Classic JPEG

JPEG2000

The new JPEG variant

OpenEXR

HDR bitmap format with up to 32-bit floats per channel

PBM

Portable bitmap format

PCX

Picture Exchange, widespread exchange format

PDF

Write-only, with embedded JPEG and JPEG2000 and fonts

PNG

Standard bitmap format

PostScript

Write-only, with embedded JPEG

RAW

Raw image files

SVG

Scalable vector graphics, read-only

Targa, TGA

Truevision Advanced Raster Graphics Array, up to 32 bits per channel

TIFF

The classic standard

XPM

X Window bitmaps (mainly for icons)

When scaling with --scale, the algorithm automatically determines which method to use. If you are not satisfied with the results it delivers, you can set the method yourself. The options in this case are:

  • --bicubic-scale
  • --bilinear-scale
  • --box-scale
  • --ddt-scale
  • --nearest-scale

Moreover, the --thumbnail fast filter generates thumbnails.

The example in Listing 1 once again illustrates the use of econvert. It produces three different output files from one input file.

Listing 1

Using econvert

 

Who Are You?

The second important program from the ExactImage suite is edentify, which is used to identify the format of an image. The example shown in Listing 2 is deliberately difficult: Identifying raw data formats is already a challenging task, and this is again aggravated by the DNG created by the conversion. Listing 3 shows the way ImageMagick handles this job with identify.

Listing 2

Using edentify

 

Listing 3

Using identify

 

Although edentify provides reasonably correct information and does not even try to guess file sizes, it outputs many error messages. ImageMagick's identify takes a different approach. First, it converts the raw data to a bitmap format, which it then analyzes.

Whether this approach makes sense is doubtful. The file sizes specified by identify are totally wrong because they relate to the bitmap files generated by the conversion, rather than the originals. Evaluating a DNG as a TIFF can be seen as reasonably correct, because DNG was designed as an extension of the TIFF standard.

The ability to display specific information about images with edentify is interesting. This is achieved by specifying a "format string" as an argument for the -f option. For example, -f "%f" gives you the file name, -f "%w" the width, and so on. Table 4 summarizes the most important variants. To connect several strings, you can use \t (tabulator), \n (newline) or \r (carriage return).

Table 4

Format Strings

Abbreviation

Meaning

%d

Directory

%f

Full file name

%t

File name without extension

%i

Path

%w

Width

%h

Height

%q

 Color depth per channel

%x

X resolution

%y

Y resolution

%z

Image depth

All told, edentify offers only limited features; again, you might need to resort to ImageMagick's identify.

Utilities

The other programs from the ExactImage suite are more specialized. For example, bardecode automatically evaluates scanned bar codes; this still works even with relatively poor images. The e2mtiff tool merges multiple images into a multipage TIFF file:

$ e2mtiff x1.jpg x2.png ... -o <out>.tiff

Multipage TIFFs are not particularly widespread nor particularly popular on Linux. However, Gimp can open and edit them. Figure 1 shows what a multipage TIFF looks like in Gimp when you load it. You can now individually edit the pages, which exist as layers (Figure 2), or convert them to new images by dragging them over the toolbox with the mouse.

Figure 1: On opening multi-page TIFFs, Gimp asks you which pages to open as layers.
Figure 2: You will find the pages as normal layers in the layers dock.

The optimize2bw program prepares scanned pages to improve their suitability for subsequent processing with OCR. The empty-page program detects blank pages, so you can discard them up front. Finally, hocr2pdf is the probably the most-used tool in the ExactImage program suite.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus