A Free and Easy to Use Image Stacking System

Robert Pavlis, Girard, Kansas USA

The extremely shallow depths of field produced by microscope objectives make it very difficult to obtain satisfactory images of any objects that are not absolutely flat. The advent of digital photography has made it possible to combine a series of images taken with different depths of an object in focus to produce an overall sharp image. Computer programs to this have been available for several years.

The commercial programs to do this tend to be extremely expensive. There are, however, several free alternatives.

There is an excellent free and open source panorama generating software package called Hugin that has been available for several years. Hugin is actually a graphical user interface program system for Helmut Dersch's Panorama Tools. The program has improved dramatically since it first became available around 2003. Recent versions are available for many operating systems, including Windows, MacIntosh OSX, and various flavours of Unix. It is now a really fantastic system to generate panoramas of scenery and other types of scenes.

The very recent versions of the Hugin package contain a command line program called align_image_stack. This program can take a series of TIFF format images, align them, and then write a new series of TIFF images with all of the points on this series properly aligned.

Hugin utilises another package called enblend-enfuse. Thus installation of hugin results in having the components of this package available. The enfuse program can take a series of image and, as the name implies, fuse them together. This program, it turns out, is extremely powerful and it is capable of fusing image stacks to make an image with extended depth of field.

Because the align_image_stack and enfuse programs are both command line programs it is very easy to use them to process a series of files using a simple shell script that provides all the command line arguments to the programs to produce the extended depth of field image without having to navigate a series of complicated menus.

 

How to Do It!

With most computer set ups, the Hugin and enblend-enfuse packages can be installed by simply downloading them from the Internet. Once one has packages with align_image_stack and enfuse present on one's computer, one can go to work.


The steps involved in producing an extended depth of field image without a shell script are as follows:


As mentioned above the sensible way to do this is to perform the two image processing operations with a single command line script that is on the execution path.

I use the following script which I call crush_stak:


#!/bin/bash

align_image_stack -a ais_ *.tif

enfuse -o result.tif --wExposure=0 --wSaturation=0 --wContrast=1 --HardMask ais*.tif


Producing an image with this script is amazingly simple. One can simply place the stack of tiff files into an empty directory and simply type "crush_stak". A few minutes later the program produces a tiff file called "result.tif"!

One could augment the script by including a preliminary line to convert the images to tiff from another format, and by adding another line at the end to convert the "result.tif" image to a more common format such as jpeg or png. However, most users would probably prefer to do the file conversions themselves.

The six images shown below were obtained using a Nikon polarising microscope. Here they are in order starting with the one of the upper part of the specimen in focus. Notice how extremely out of focus portions much of the image is.

initial images

The image below was obtained by simply running the script shown above using the full sized original Canon digital single lens reflex camera's jpeg images converted to tiff.

initial images


A set of thirteen images of the mineral celestite was produced using the same Canon digital single lens reflex camera using a Wild M7A equipped with a LOMO MBS-10 single lens reflex camera adaptor. The resulting stack was processed by simply running the same script described above to produce the following image:

initial images

The image shown above is a dramatic improvement over any of the original thirteen images. The specimen was thick, so only a narrow zone was in focus in each of the originals. The original specimen had many tiny spots on the crystals, the clarity of these shows just how well this particular system functions.


The great thing about this particular system of stacking images is the extreme simplicity of use once it has been set up. Obtaining the final stacked image is simply a matter of putting the tiff images taken at different focus depths into an empty directory and running the shell script described above!!

A large stack of images will obviously tend to produce better results, but it takes much longer for the computer processing. Because a shell script is used to control the process, the users still need only start the same script whether the number of files to be incorporated are only five or six or two hundred!

I have developed this method using Ubuntu. The Ubuntu repository contains all the programs described above. They can be all be obtained from Internet connexions using the Ubuntu apt-get program or its synaptic package manager. Ubuntu, by the way, is absolutely the easiest computer operating system to install that I have ever seen! It is reasonably secure, there are thousands of high quality free open source programs available pre compiled in its repository, and above all, it is stable and computer vandals and criminals have difficulty getting past its security. The assortment of free open source programs in the repository is amazing. There are especially large numbers of scientific programs and graphics related ones. Furthermore, Ubuntu itself is free and its installation disk can be simply downloaded from the Internet. (Its default window manager is Compiz, the famous compositing window manager with all its extreme visual effects running over the commonly used gnome.)

The system described, however, should work with most other operating systems without difficulty, since the described programs have been ported all over the place. The critical thing is to remember that only recent versions of hugin contain the essential align_image_stack program.

All comments to the authors Robert Pavlis are welcomed.

Additional images

 

  Microscopy UK Front Page
Micscape Magazine
Article Library


© Microscopy UK or their contributors.

Published in the June 2009 edition of Micscape Magazine.

Please report any Web problems or offer general comments to the Micscape Editor.

Micscape is the on-line monthly magazine of the Microscopy UK website at Microscopy-UK  


© Onview.net Ltd, Microscopy-UK, and all contributors 1995 onwards. All rights reserved. Main site is at www.microscopy-uk.org.uk with full mirror at www.microscopy-uk.net .