Focus stacking with Fiji/ImageJ and Enfuse
Oct 13, 2012
3
Fiji is a free software package derived from ImageJ. Fiji adds some handy pre-installed plugins and an automatic updater. The package runs atop of Java virtual machine, so it needs to be installed first.
>Fiji is an image processing package. It can be described as a distribution of ImageJ (and soon ImageJ2) together with Java, Java 3D and a lot of plugins organized into a coherent menu structure. Fiji compares to ImageJ as Ubuntu compares to Linux.
>The main focus of Fiji is to assist research in life sciences.
As the software is made to operate with microscope imagery in mind, it handles various stack formats really well, even multi-dimensional ones. Enfuse on the other hand is a small application made to extend image's dynamic range, but it can used to create depth of field stacked images with the right options.
1: Loading a stack of images to Fiji: Image files can be drag and dropped to Fiji's interface, then each image is opened in its own window. To create a stack from opened images, navigate to Image/Stacks/Images to stack or use the same command under the button labeled Stk. All open images are now congregated into single window.
Sometimes the order of images is messed up (I think Windows Explorer has bug where drag and dropped files are opened in wrong order), the command to order the stack by label (file name becomes the frame's label in stack) can be found under menu command Image/Stacks/Manipulation/Stack sorter, there sort by label. Sorting is needed because the plug-in we use to align the images will align each image to its neighbors only.
2: Aligning images using SIFT: The command to align the images in stack can be found under Plugins/Registration/Linear stack alignment with SIFT. A dialog pops up, I've left the default values as they are except for the transformation, which I've changed to similarity. This moves, rotates and scales the images to fit, affine transformation seems to also shear the images which we don't want.
The plugin runs at speed of about 0.2 seconds per megapixel (on my 6 core machine), which is faster than Photoshop's or Hugin's alignment process. The first image of the stack is the anchor image, every other image is transformed to align to it. This is a good thing to keep in mind, because the magnification changes when focusing or using a macro rail.
After alignment is done, new stack window pops up and the images can be saved from File/Save as/Image sequence.
3: Creating DoF stacked image with Enfuse: I'm using EnfuseGUI, there are loads of other options for different platforms and of course there's the option of command line use for computer-savvy people. When creating depth of field stacks with Enfuse the important options are the weighting of local contrast, use of hard mask, size of contrast window and optional local contrast enhancement. Enfuse's manual goes into detail, what these options do behind the scenes.
Anyway, in EnfuseGUI set maximum weight ot contrast (zero exposure and saturation), tick force hard blend masks, and set contrast window size to 7-11 pixels. It is good idea to test how the contrast window size affects the final image: sometimes, with low values (1-5 pixels), there is a "glow" around hard edges which goes away with bigger values for contrast window size.
Finally, there's the local contrast enhancement (LCE for short) section of the GUI. It has boxes for edge scale, LCE scale and LCE factor. I've used values of 1; 5 and 10, respectively. The bigger the LCE factor, the bigger the local contrast boost. Using these options slows down the processing a bit.
After Enfuse has done its job, you should end up images that look like this:
Cypripedium calceolus, 34 images stacked using 105mm VR Micro-Nikkor at f8. Focused with a rail.
Unknown insect. 25 images with 105mm VR Micro-Nikkor at f11. Focused with a rail.
Phalangium opilio. Nine images with the aforementioned Nikkor at f8 and a rail.