Pat David Focus Stacking Macro Photos (Enfuse)
Pat David Focus Stacking Macro Photos (Enfuse)
ABOUT ARCHIVE
◑ THEME
This article is about focus stacking, for exposure blending, see here:
Automatic Exposure Blending with Enfuse (HDR-ish)
Focus Stacking
So, what if you want a deeper depth of �eld in your shots? Well,
there’s a neat technique called “Focus Stacking” where you will take
multiple images, with the only thing that varies between them is the
focal point. Look again at the lead image, and speci�cally notice how
the focus plane shi�s along the length of the gun body.
The problem, of course, is that you now have multiple images, all
with di�erent focus planes. How can you combine them all into one
image where the di�erent in-focus areas are all combined?
Well, we’re going to use the open source Enfuse to do this dirty work
for us. First, though, we need to make sure the images are properly
aligned �rst…
Don’t Panic. To follow along, basically, put all of your focus stacked
images into a single directory. Open a command prompt, and
navigate to that directory.
Assuming your Hugin installed in the same place as mine, you can
run the command as I show above. The -m switch will optimize the
�eld of view for all images except the �rst. The -a OUT will pre�x all
the output �les as OUT…tif, and FILE1 FILE2 etc… are the names of
each of your focus stacked images you are starting with.
When it’s done, you’ll have a few new images in your directory
named OUT000#.tif. These are your newly aligned output images,
and will be what we work with from here on out.
Enter Enfuse
At this point you’ve got your images aligned perfectly (hopefully),
and now all that is le� is to mask each image so only the sharpest,
in-focus portions show through. This is exactly what we are going to
get Enfuse to do for us.
Enfuse can be run from the command line (the same bin/ directory
where align_image_stacks was located) as part of a Hugin
installation, or there is a GUI called EnfuseGUI that will expose all
the options along with fast previews.
enfuse \
--exposure-weight=0 \
--saturation-weight=0 \
--contrast-weight=1 \
--hard-mask \
... \
--output=output.tif \
input-<0000-9999>.tif
If you’re happy with these results, then stop here. That’s it! Quick,
relatively painless, and you’re happy with the results. Go have a
beer! (Seriously, many people will be �ne with these results, and
don’t have to head any further).
One of the options that I �nd to produce slightly better results are to
use the L* channel of LAB colorspace as the grayscale projector to
Enfuse (don’t worry about the technical stu� - basically use the L*
channel in LAB to create the masks as opposed to averaging).
If you notice some haloing e�ects around high contrast edges, you
can mitigate them a bit by increasing the size of the box Enfuse uses
to evaluate contrast detection. The option to adjust this box size is:
–contrast-window-size=X Where X ≥ 3. The documentation points out
that values larger than 5 might produce blurry images, but I would
experiment with values all the way up to 9 to see how it e�ects your
�nal output.
There is another good option to tweak your �nal output, and that is
to enable the Laplacian Edge Detection algorithm. Laplacian Edge
Detection can be enabled by passing a positive value to: –contrast-
No problem! We can just switch gears here at this point and fall back
to the trusty command line. So at this point, besides the base
parameters, I am going to add in contrast-edge-scale to enable the
Laplacian Edge Detection algorithm:
enfuse \
--exposure-weight=0 \
--saturation-weight=0 \
--contrast-weight=1 \
--hard-mask \
<span style="color:#00FF00;">--gray-projector=l-star \</span>
<span style="color:#00FF00;">--contrast-edge-scale=0.3 \</span>
--output=output.tif \
input-<0000-9999>.tif
You can compare the results of adding in the l-star option and using
the Laplacian edge detection at 0.3 pixels below:
2. Try Enfuse with the base focus stacking parameters to see if you
are happy with the results. enfuse --exposure-weight=0 --saturation-
--output=base.tif OUT*.tif
4. If there are halos around high contrast edges, you can try
increasing the contrast-window-size a bit. ( --contrast-window-
size=5 ). enfuse --exposure-weight=0 --saturation-weight=0 --contrast-
OUT*.tif Modify the value between 0.1 and 0.5 to see which result
is best for you.
Thoughts
If you want a truly sharp macro shot with a large, smooth depth of
�eld, you’ll be taking a lot of photos. Seriously. I’ve seen 100+ images
used for a single macro shot. Look at these:
Some References
PAT DAVID
ABOUT ARCHIVE RSS TOPICS
Unless otherwise noted, this work by Pat David is licensed under a Creative
Commons Attribution-ShareAlike 4.0 International License.
Permissions beyond the scope of this license may be available at https://patdavid.net
/about.