Focus Stacking: Combining Images for a Sharper View

There’s a tradeoff involved when you try to focus on things under a microscope. The higher the magnification the less you’re able to focus on at a time. Images 1, 2, and 3 in Figure 1 show a catalpa pollen grain under 400x magnification. In each image the microscope is focused slightly differently to bring a different level of the pollen grain into focus.

Three images (image 1, image 2, and image 3) are stacked together to create a final, focus-stacked image that is in better focus (has a larger depth of field). The images are of catalpa pollen grains at 400x magnification, stacked using Hugin Tools.

I tried two methods for doing the image stacking. The first was with the command-line programs in Hugin Tools, while the second was by hand using GIMP.

Hugin Tools

The method for focus stacking with Hugin Tools is described here by Patrick David and here by Edu Perez. It requires two commands, one to align the images, because focus-stacking requires very well aligned images, and another to stack them together.

Align the images using align_image_stack:

align_image_stack -m -a als_ catalpa-c[123].tif

This command takes three image files (catalpa-c1.tif, catalpa-c2.tif, and catalpa-c3.tif) and produces three aligned images prefixed with “als_” (als_0000.tif, als_0001.tif, and als_0002.tif).

The images are stacked together using enfuse (details here).

enfuse -o catalpa-pollen-out-b.tif --exposure-weight=0 --saturation-weight=0 --contrast-weight=1 --hard-mask --contrast-window-size=9 als_000?.tif

which produces an output file called catalpa-pollen-out-b.tif.

Focus-stacked image of a catalpa pollen grain using Hugin Tools. (Magnification 400x).

GIMP

Focus-stacking with GIMP requires opening all the files as layers and adding transparency masks to the layers to leave behind just the areas that are in focus. The general method is shown in this GIMP tutorial.

Aligning images by hand and then selecting the areas to cut out can be quite tedious.

400x magnified, catalpa, pollen grain that was focus-stacked by hand with GIMP.

Notes

Two key things to keep in mind are:

  • the better aligned images are to start with the easier they are to focus-stack. Aligning images is tedious even with align_focus_stack;
  • the quality of the camera matters a lot. The images above were taken with a Moticam 2 megapixel camera attached to the microscope to reduce misalignment. The image below, however, was taken with a point-and-click, 6 megapixel camera down the eyepiece. You can see a lot more detail.
Catalpa pollen grain taken with a higher resolution camera.
Higher resolution, focus-stacked image of catapa pollen grain. (magnification 400x)

The Creek in Winter at Night

The creek under a waxing moon.

Trivia night let out at midnight. The ground was still covered with a smooth layer of snow. The meltwater from the daytime sun had refrozen to make the snow crisp on top, like a cold crème brûlée. The moon was close to full. I had my camera.

The moon reflected in a pool partially covered by ice.

I spent about twenty minutes traipsing through the woods along the banks of the creek. Not having a tripod made it impossible to get long-exposure without setting the camera down somewhere stable, so I ended up lying prone on the snow. Whilst my jacket and sweater made my top half well insulated, there was just a single layers of broadcloth separating my legs from the snow. I didn’t have a problem with the cold, but my body heat melted the snow, and I got wet.

But it was worth it.

How to Watch a Meteor Shower

A meteor shoots past the Milky Way. Image by L.Brumm Photography and Design.

Space.com has an excellent guide about the best way to observe meteor showers; dress warm; after midnight; be patient). The Lyrid meteor shower is on this week.

To take good photos of a shower you’ll need to do long exposures or get lucky. Details on the photo above here.

Morning Fog

Early morning fog over the lake.

There’s a place on the road to school where you crest a little rise and the St. Albans golf course opens up before you. “Zen-like,” I’ve heard it described. On one lovely fall morning last week the view was absolutely ridiculous. I had to stop.

Resisting the coming winter, warmer air from down south just pushed over the hills overnight, trapping the cooler air in the valley, creating a thermal inversion that trapped a layer of fog just below the tops of the hills. Small tendrils of mist were rising off lake in the bottom of the valley, feeding the fog layer as the cooler valley air condensed the water vapor evaporating off the still warm lake.

Combine the fog, mists, early morning sunlight just beginning to reach into the valley, and the brilliant fall colors contrasting against the still-green lawns, and the result was absolutely amazing.

Not being able to leave well enough alone, I've also put together this "3d" gif. It does show the fog on the lake nicely though.