Many modern cameras allow for automated focus stacking (focus bracketing in Canon speech). 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
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!