DPReview.com is closing April 10th - Find out more

Focus stacking with Fiji/ImageJ and Enfuse

Started Oct 13, 2012 | Discussions
jannefoo Regular Member • Posts: 310
Focus stacking with Fiji/ImageJ and Enfuse
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.

 jannefoo's gear list:jannefoo's gear list
Sigma APO Macro 180mm F2.8 EX DG OS HSM Sigma 14mm F1.8 Art Nikon D800 Nikon 1 J5 Samyang 85mm F1.4 Aspherical IF +9 more
mfloreen New Member • Posts: 1
Re: Focus stacking with Fiji/ImageJ and Enfuse
1

Thank you for detailing all this out! I had been playing with settings in ImageJ and Enfuse, but you have saved me many hours of experimenting.

Thanks for sharing this info. I've registered for this forum just so that I could say how much I appreciated your post!

 mfloreen's gear list:mfloreen's gear list
Canon EOS 6D
John K Veteran Member • Posts: 9,870
Re: Focus stacking with Fiji/ImageJ and Enfuse
1

Meh -I don't focus stack

Tech Specs: Canon 1D Mark III (F11, 1/250, ISO 200) + a Canon MPE-65mm macro lens (@ almost 4x) + a diffused MT-24EX.

-- hide signature --

Also known as Dalantech
My Book: http://nocroppingzone.blogspot.com/2010/01/extreme-macro-art-of-patience.html
My Blog: www.nocroppingzone.com
My gallery: www.johnkimbler.com
Macro Tutorials: http://dalantech.deviantart.com/gallery/#Tutorials
Always minimal post processing and no cropping -unless you count the viewfinder...

Oldan New Regular Member • Posts: 499
Re: Focus stacking with Fiji/ImageJ and Enfuse

Excellent work.

Icedragon05 New Member • Posts: 1
Re: Focus stacking with Fiji/ImageJ and Enfuse

Hi

Very new at this - I am attempting to stack a set of images, initially in .nef and now in .tif without much success. I'm sure its very basic but after loading Fiji / J2 open the set of images and access the toolbar Image - Stacks - Images to stack, I get a popup with "at least 2 images must be open".

The .tif open "fullscreen" but the .nef opens in 2 inch square window in IJ1 and creates an exception in Fiji as below

Am I missing something very obvious... config issue?

(Fiji Is Just) ImageJ 2.0.0-rc-15/1.49h; Java 1.6.0_24 [64-bit]; Windows 7 6.1; 891MB of 6129MB (14%)

java.lang.ArrayIndexOutOfBoundsException: 2

at io.scif.filters.PlaneSeparator.openPlane(PlaneSeparator.java:291)

at io.scif.filters.PlaneSeparator.openPlane(PlaneSeparator.java:208)

at io.scif.filters.AbstractReaderFilter.openPlane(AbstractReaderFilter.java:225)

at io.scif.filters.AbstractReaderFilter.openPlane(AbstractReaderFilter.java:191)

at io.scif.img.ImgOpener.read(ImgOpener.java:808)

at io.scif.img.ImgOpener.read(ImgOpener.java:793)

at io.scif.img.ImgOpener.read(ImgOpener.java:775)

at io.scif.img.ImgOpener.readPlanes(ImgOpener.java:761)

at io.scif.img.ImgOpener.openImgs(ImgOpener.java:362)

at io.scif.img.ImgOpener.openImgs(ImgOpener.java:257)

at io.scif.img.ImgOpener.openImgs(ImgOpener.java:145)

at net.imagej.DefaultDatasetService.open(DefaultDatasetService.java:266)

at net.imagej.DefaultDatasetService.open(DefaultDatasetService.java:250)

at net.imagej.io.DatasetIOPlugin.open(DatasetIOPlugin.java:78)

at net.imagej.io.DatasetIOPlugin.open(DatasetIOPlugin.java:50)

at net.imagej.legacy.plugin.DefaultLegacyOpener.open(DefaultLegacyOpener.java:134)

at net.imagej.legacy.DefaultLegacyHooks.interceptFileOpen(DefaultLegacyHooks.java:327)

at net.imagej.legacy.DefaultLegacyHooks.interceptRunPlugIn(DefaultLegacyHooks.java:150)

at ij.IJ.runPlugIn(IJ.java)

at ij.Executer.runCommand(Executer.java:131)

at ij.Executer.run(Executer.java:64)

at java.lang.Thread.run(Thread.java:662)

Keyboard shortcuts:
FForum MMy threads