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)

A Catalpa Tree Flower Under the Microscope

More testing of the higher powered stereo-microscope with this flower specimen from a catalpa tree on campus.

Anthers with pollen grains (~25x).

The catalpa tree leaf and flower for reference.

Large catalpa leaf and two flowers.
Detail of longitudinally bisected flower (~7x).
Closeup of petal (~35x).
The colors on the petals come from cells having different colors (~90x).

Lavender Flowers Up Close

Lavender flowers on the stage of the reflecting, stereo microscope.

In addition to the basic stereoscopes with their fixed 10x and 30x magnifications, we also acquired a zoom stereoscope for more serious research projects. I tried it out with a sprig of lavender blossoms.

Closeup of lavender flowers. Magnification 7x.

The clips on the stage weren’t particularly useful for holding something as small as a single flower, so, to see into the flower, I had to improvise with some of the dissection gear.

Holding the lavender flower upright on the stage with a dissection probe.

At larger magnifications, the focal depth is pretty small so it’s tricky trying to get the big picture. Even thought the camera didn’t quite capture it, you can make out the pollen grains.

Looking into a lavender flower from the top. Magnification ~45x.

I tried slicing the flower longitudinally to get a better look inside, and to see how difficult it would be to identify the major parts.

Longitudinal section of a lavender flower. Magnification 14x.

The photos turned out well using a point-and-shoot Nikon camera through the eyepiece, but even these pictures did not capture all the detail visible to the eye.

Lavender flower sliced longitudinally. Two stamens are clear visible. Magnifications ~50x.

With the 2x objective attached, the microscope gets up to 90x magnification, but it becomes very hard clearly see anything after about 60x. All in all, the optics are good, and the lights bright enough to make for a very nice microscope.

Green Onion Under the Microscope

Seed head of a green onion. 10x magnification.

A new set of stereo, reflected-light, microscopes came in last week, and I’ve been testing them out. MPU has a good eye for these things, so I asked him to collect some samples for examination.

The first thing he came up with was this beautiful green onion. The seed head has some remarkable colors, and the microscopes are of good enough quality that we could examine in quite good detail at 10x magnification. We were even able to see a few small insects hanging out on the seed head that would have been invisible to the naked eye. They didn’t like the light, however, and hid before I could get a good photo.

Roots of a green onion. 10x magnification.