I have tried a few different programs that let you increase depth of focus by stacking pictures that are shot at varying focus distances. Most of those programs will readily fail when the subject is too complex or the focus depth is too extreme.
Focus stacking is mostly used in two different realms, namely landscapes and macro photography. Landscape photographers usually want maximum depth of field and maximum resolution, which can be had by stacking photos shot at the sharpest aperture and at multiple focus distances. Macro photographers know only too well that a single close-up can have paper-thin depth of focus; combining a dozen or more shots is often necessary to get sufficient depth of focus.
I have had too much grief using Photoshop and Hugin tools, but a (free) program that works pretty well for me is called CombineZM by Alan Hadley.
Stacking pictures requires a lack of image movement, so wind can mess up your plans. The pictures need consistent exposure, so manual exposure works best (at a constant aperture). For macro work, I like to use my Nikon PB-4 bellows (with its rack-and-pinion focus rail) to easily move the camera/lens combination from shot to shot, shifting focus by maybe half of a millimeter per shot. Good luck finding a Nikon PB-4 bellows.
The default settings in CombineZM don’t always work the best for me, so I thought I’d share how I make it work for me. It bears mentioning that “macro” in CombineZM means “run a sequence of steps” and not anything to do with close-ups.
My most successful recipe to stack pictures is this:
Post process and convert your pictures into TIF format (16- bit with LZW compression is what I use) using your favorite image editor.
Run CombineZM (I use it in Windows7 and Windows10, but it works in other operating systems, too).
Select File | *New and then select the set of TIF pictures to stack (select in focus-order). Wait until the pictures are loaded.
Select Macro | Do Weighted Average. I have less success using “Do Stack” or “Do Weighted Average Correction”.
After it finishes, use your mouse to draw the diagonals of a rectangle around the ‘good’ part of the result.
Select File | Save Rectangle As. I just save the result as JPG, with typically 95% quality.
Here’s a sample finished shot, which is from a stack of 10 files:
“Do Weighted Average” macro to create the stack
I actually took even more shots in front and behind of what was used above. The software started to mess up with this many pictures, so I omitted some shots to achieve the result shown above.
“Do Weighted Average” with even more pictures in the stack. Note the evil ‘ghosting’.
“Do Stack” macro. Note strange artifacts using this option.
What a focus stack looks like before you crop it.
Typical single shot depth of focus (60mm f/10)
Depending upon your subject, you may have to iterate on the selected options or perhaps how many pictures you can stack. Life is rarely simple…
Make sure your subject is a bit smaller than the frame, because you will have to crop the edges of the “stack”.
Focus stacking is one of those techniques that takes a little tenacity. There are many different tools that can stack pictures, with varying degrees of success (or failure). This is one of those digital tricks that seems to defy optical physics.
If you're willing to put in the effort, the results can be quite rewarding.