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 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.
convert img-from img-to
for i in Img*.x do echo $i convert AVS:$i `basename $i .x`.png done
convert AVS:Img00001.x +matte +page -depth 8 -type TrueColor Img00001.png
convert -flip img-from img-to
convert -scale 50% img-from img-to
convert -thumbnail 50% img-from img-to
convert -thumbnail 170x img-from img-to
convert -thumbnail x128 img-from img-to
Note that to upscale an image (for example a dialog screen-capture for a paper) it is better to use the Upsize GIMP plugin.
convert img-from -colorspace Gray img-to
convert +dither img-from -colors 64 img-to
convert img-from -posterize 6 img-to
pnmtotiffcmyk
is one of the NetPBM tools)
convert img.jpg img.pnm pnmtotiffcmyk -lzw img.pnm > img.tif
convert img.jpg PNM:- | pnmtotiffcmyk -lzw > img.tif
convert img.jpg PNM:- | pnmtotiffcmyk -lzw > img.tif imgtops img.tif > img.eps rm img.tif
convert img-from -draw "text 50,10 '© Mario Valle 2007'" img-to
convert img-from -annotate 0x0+50+10 '-font Arial -pointsize 24 ciao!' img-toThe list of available fonts can be obtained with
convert -list type
convert img-from -draw "image Over 50,10 0,0 logo.tif" img-to
convert -geometry 512x80! XC:red filler.png
montage -tile 2x2 -geometry 512x512 img[1234].png tot.png
montage -tile 1x2 -mode Concatenate image.png chart.png result.png
montage -label '%f\n%wx%h' '*.{jpg,gif,png,GIF,PNG}[1]' \ -tile 6x -frame 5 -shadow -geometry 120x90+5+5 ../INDEX.htmlOnce generated you will find in the parent directory the two files
INDEX.html
and
INDEX.gif
and in the same
directory the file INDEX_map.shtml
that can be deleted. Then you should move INDEX.html
and
INDEX.gif
to the same directory of the images and edit INDEX.html
changing the
../INDEX.gif
reference to INDEX.gif
# Add a border to the images convert -scale 1020x1020 -border 2x2 front.png x-front.png convert -scale 508x508 -border 2x2 side.png x-side.png convert -scale 508x508 -border 2x2 top.png x-top.png # Then combine them into the final.png image montage -tile 1x2 -mode Concatenate x-top.png x-side.png x-right.png montage -tile 2x1 -mode Concatenate x-front.png x-right.png final.pngAll those operations are performed by the provided three-views.sh shell script. The script adds also a small annotation to the three panels. To experiment here are the three images used to test the script: front view (goes on the left), top view (goes on the top right) and side view (goes on the bottom right).
convert -scale 50% img-from img-to
convert image-in -filter filter -support support -resize new-widthx image-out
For my site I defined a specific format for tables of commented images. Examples are the Representation in chemistry and Visualization examples 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.
-delay
parameter is the time between frames expressed in 1/100th of second.
The argument of -loop
instead sets the number of repetitions of the sequence (zero means loop forever):
convert -delay 50 -dispose Background +page Img*.png -loop 0 animation.gif
mplayer -vo gif89a:fps=0.5:output=animation.gif \ -mf w=512:h=512:type=png:fps=0.5 mf://Img\*.pngIt is important to specify the image size and the fps value twice.
mplayer -vo gif89a:fps=1.5:output=animation.gif movie.avi
convert -delay 50 -dispose None +page Img*.png -loop 0 animation.gif convert animation.gif -deconstruct animation-optim.gifThe resulting size depends on how small is the changing area between frames.
convert
has problems with big animations (like 200 frames 1024x768). The solution is to scale the frames and to decimate them (like one frame every 4 or 5).convert Img*.png GIF:- | gifsicle --delay=50 --loop --optimize=2 \ --colors=256 --multifile - > out.gif
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 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 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.
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 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
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
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:
jpegcrop
: to rotate loselessy an image.jhead
: an Exif Jpeg header and thumbnail
manipulator program.The library can be downloaded from various sites: