Mario Valle Web

Image tools

After producing beautiful images, sometimes some form of image postprocessing is needed. For this, my Swiss Knife tool is ImageMagick. Here I collect some useful command lines I used for visualization images post processing.

A more general collection of ImageMagick useful tricks can be found on the excellent Examples of ImageMagick Usage pages. More complex tricks can be found on the previous version of this page.

At the end a quick coverage of other image manipulation tools. They have been tried and found useful for some needs.

ImageMagick installation

ImageMagick is available by default on Linux and can be installed and used on Windows. On Windows be careful with the definition of the PATH variable: ImageMagick install directory should come first, otherwise when you launch convert, the windows convert filesystem command will be called.

For scripts that should work on windows and Linux I suggest installing Cygwin or MinGW and run them under sh from a command window.

ImageMagick techniques

  1. Basic format conversion
  2. Crop and scale
  3. Color manipulation
  4. Drawing and annotations
  5. Assemble images
  6. Filter images
  7. Create table of images
  8. Create animations

Basic format conversion

Crop and scale

Note that to upscale an image (for example a dialog screen-capture for a paper) it is better to use the Upsize GIMP plugin.

Color manipulation

Drawing and annotations

Assemble images

Filter images

Create table of images

For my site I defined a specific format for tables of commented images. Examples are the Representation in chemistry and Visualization examples [italiano] pages.

To help this type of pages creation, I have created a small shell script (mkthumb.sh) that creates thumbnail and big images of all the images found in the current directory. The resulting images are put in a subdirectory called 'out'.

The script creates also a file called mkthumb.html that contains the skeleton of the boxes containing the image and its description to be included in the final HTML page. This page needs a CSS stylesheet to format correctly and a print stylesheet to print correctly.

The script works on Linux and Windows (using Cygwin or MinGW) and optionally uses PNGOut (see below) to optimize the size of the resulting PNG files.

Create animations

Other tools

The GIMP

Image manipulation program that offers almost all the functionalities needed for visualization postprocessing without the cost (and completeness) of Photoshop. Look at the pile of pages on GIMP vs. Photoshop where you can find a comparison between the two tools.

The following functionalities are really interesting for postprocessing:

Gfig: for very limited image annotation with circles and lines. But it seems better to load the image inside Inkscape or PowerPoint to add annotations and then re-export the result as an image. Gfig is available under Filters → Render → Gfig.

Bump Map filter: could make molecular structures (and similar cartoon-like images) more definite. It is available under Filters → Map → Bump Map.

Antialiasing: could be interesting when scaling up a picture. Select Filters → Map → Map Object. Here select Plane, lighting none, antialiasing on with depth 5.

Colorblind simulation: to see how an image looks like to a colorblind person. Select View → Display filters → Color deficient vision.

Here is a good article which talk about the few things that the GIMP lacks (Thanks Lisa "Vegas Mommy"!).

LittleCMS

LittleCMS offers a library of functions for the creation and manipulation of ICC color profiles. One of the goal of the color profiles is to remap an image colors so it prints correctly on a given printer. More information and various demos are available from the LittleCMS page.

The jpegicc application that comes with LittleCMS applies a given profile to a JPEG image. In the following example it applies the profile for a HP color printer to an image; the original image is assumed to follow the sRGB color space:

jpegicc -oHP1200PS.icm input.jpg output.jpg

A set of profiles can be found on the PANTONE support page.

The GIMP offers a preview function for color correction (View → Display Filters → Color Proof). This function is more or less the reverse of the functionality offered by LittleCMS: it shows how the image will look on a printer with the given profile.

PNGOut

PNGOut is a PNG optimization tool written by Ken Silverman. I have no idea how it works, but it works well. It produces smaller PNG files, good for an image-filled web page. A porting to Linux and Mac exists (link on the same page).

A nice front-end to PNGOut is PNGGauntlet (Windows only) that can optimize and compress all images contained in a directory. Beware that it works also on JPEG images, but for them almost always the file size increase dramatically. If you find that some JPEG shrink, remember to adjust the referring web page because the image type changes from JPEG to PNG.

Photoshop

OK, this is the perfect tool for whatever image manipulation you can dream of. Unfortunately it costs a lot and it is not so critical for normal scientific visualization images.

But some really handy Photoshop functionalities are (still) not available in The GIMP. For example, one of my users employs Photoshop to correct colors for printing.

Again read the comparison between The GIMP and Photoshop.

Gifsicle

Gifsicle is a multiplatform command-line tool for creating, editing, and getting information about GIF images and animations. For example making a GIF animation with gifsicle is easy:

gifsicle --delay=10 --loop *.gif > anim.gif 

sam2p

The main streight of sam2p is its abily of produce small EPS files from raster images. This is often reqired by LaTeX paper submission. Furthermore the tool is multiplatform. There is an ample set of accepted input formats:

$ sam2p
This is sam2p 0.49.
Available Loaders: PS PDF JAI PNG JPEG TIFF PNM BMP GIF LBM XPM PCX TGA.
Available Appliers: XWD Meta Empty BMP PNG TIFF6 TIFF6-JAI JPEG-JAI JPEG PNM GIF89a+LZW XPM PSL1C PSL23+PDF PSL2+PDF-JAI P-TrOpBb.
Usage:   sam2p <filename.job>
         sam2p [options] <in.img> [OutputFormat:] <out.img>
Example: sam2p test.gif EPS: test.eps

JPEG Group provided utilities

There is a set of utilities provided together with the official libjpeg. One of them (cjpeg – compress an image file to a JPEG file) provides various methods to compress and optimize the named image file, or the standard input if no file is named, and produces a JPEG/JFIF file on the standard output. The currently supported input file formats are: PPM (PBMPLUS color format), PGM (PBMPLUS gray-scale format), BMP and Targa. You can look at its man page.

The following trick is explained in the POV-Ray FAQ. Basically you call cjpeg with the following switches:

cjpeg -sample 1x1,1x1,1x1 -quality 75 -optimize

Another set of utilities that work on JPEG files are:

The library can be downloaded from various sites:

Other suggestions