Many modern cameras allow for automated focus stacking (focus bracketing in Canon speech).

A quick excursion how this works on a Canon RP (and similar R models):

  • Enable Focus-Bracketing
  • Set the maximum number of images, i.e. 40 or more for macros - for landscape it will often only be 10 images that are taken. The camera will decide anyway when to stop (When focus reaches infinity), thus you can leave this on a high value just to be sure! Macro images require more photos than landscape (my rule of thumb...)
  • You can adjust the focus increment, for me 4 is fine. You might decrease it for smaller aperture numbers.
  • Now, focus on the nearest distance you want to have sharp in the image
  • Maybe enable 2 second timer to reduce vibrations on the tripod and press the shutter button once.
  • On a bright day, this takes only a second to gather all the images!

Using enfuse and the tools from hugin-tools, it is quite easy to create a nice focus stacked image out of the set of images. These commands came from foto.schwedenstuhl.de.

I use darktable to collect my photos, so the first step is to export the set of images as .tiff files.

In the next step, we use the tool align_image_stack from hugin-tools to align the images:

align_image_stack -v -m -a Aligned *.tif

It seems counter-intuitive to do the alignment, even if we used a tripod. But there is a reason for this: during focusing, the actual focal length shifts a tiny bit (This phenomena is also called "focus breathing"). For landscape photography, this might not necessarily be required (I tested it). But still, you can see a small effect of this even in landscape images. For macro-photos, this matters a lot!

Now, we can call enfuse to create the fused image:

enfuse \
    --exposure-weight=0 \
    --saturation-weight=0 \
    --contrast-weight=1 \
    --hard-mask \
    --contrast-window-size=9 \
    --output=fused.tif \
    Aligned*.tif

You can play around with the options, but these were already recommended elsewhere and seem to be a good starting point.

Here is an example. This is the first image of the stack, notice the very shallow focus:

Now, the focus stacked image - you can clearly see that the focus is over the full depth!