The problem, with numbers
Depth of field shrinks dramatically as you get closer. At a 1:1 macro magnification at f/8, the zone of acceptable sharpness is under a millimetre. An insect’s eye is sharp and its wingtip is not, and there is no aperture that fixes it: stopping down to f/22 buys a little more depth and loses sharpness everywhere to diffraction.
The same problem, less extreme, appears in product photography: a bottle photographed from close range has a sharp label and a soft neck. And in landscape, where a foreground rock a metre away and a mountain at infinity cannot both be sharp at a usable aperture.
Focus stacking takes several frames at different focus distances and combines the sharp parts of each.
Shooting a stack
- Tripod, always. The frames must align to the pixel.
- Manual focus, moved in small steps between frames, from nearest to furthest. The steps must be small enough that the sharp zones overlap; if they do not, you get a band of softness through the middle of the result.
- Do not change the aperture. Depth of field must be consistent.
- Move the focus, not the camera, unless you have a macro rail: moving the camera changes the composition and the perspective.
- How many frames: a product shot might need 5 to 15, a macro subject 30 to 100. Many cameras now have an automatic focus bracketing mode that takes the whole sequence for you.
- Use a remote or the self-timer so nothing shifts between frames.
Focus breathing, and why alignment is not optional
As the lens refocuses, its effective focal length changes slightly. The frame therefore changes magnification across the stack, a phenomenon called focus breathing, so the last frame is slightly more or less magnified than the first.
That means the frames do not simply overlay; they have to be scaled as well as shifted. Every stacking tool does this, and it is why the outer edges of a stacked image are unusable and get cropped.
align_image_stack -m -a aligned_ -v *.tif
enfuse --exposure-weight=0 --saturation-weight=0 --contrast-weight=1 \
--hard-mask -o stacked.tif aligned_*.tifThe -m flag lets align_image_stack correct for scale as well as position, which is exactly the focus-breathing correction. The enfuse weights tell it to choose pixels by local contrast (sharpness) rather than by exposure, which is the focus-stacking mode. Both tools are free and part of Hugin.
How the combination works, and where it goes wrong
The algorithm computes local contrast at every pixel in every frame and picks the frame where it is highest, because the sharpest version of a region has the most local contrast. Then it blends the choices to avoid hard transitions.
The failure follows directly from that. Where a sharp foreground edge sits against a background that is sharp in a different frame, the algorithm has to choose between two regions that are both locally high in contrast. What you get is a halo: a ring of blurred or doubled detail tracing the foreground object’s outline.
This is most visible on:
- Thin structures (antennae, hairs, stamens, wires) where the blurred version in other frames is wider than the sharp one, so the blur survives around the sharp core.
- Objects against a bright background, where the out-of-focus version of the object was larger and lighter.
The fixes: more frames with smaller focus steps, so the transitions are gentler; hand-retouching the halo afterwards from one of the source frames; and, in Photoshop’s stacking, adjusting the blend or masking manually. Photoshop’s Edit > Auto-Blend Layers with Stack Images does a reasonable job and leaves the masks editable, which is its main advantage over a command-line tool.
Movement kills it
Anything that moves between frames appears in the wrong place in the frames where it was sharp. A breeze on a flower over a 40-frame stack is fatal. So:
- Work indoors, or on a still day, or shield the subject.
- Shoot the stack as fast as the equipment allows.
- For living subjects, a stack is usually impossible, which is why macro photographers of insects work early in the morning when the subject is cold and still, and why some subjects are only ever photographed in a single frame.
Free software
- Hugin’s align_image_stack + enfuse, as above. Free, scriptable, excellent.
- darktable can align and blend, though it is not its primary purpose.
- GIMP with the G’MIC plugin has a focus-stacking filter.
- Photoshop does it with Auto-Align plus Auto-Blend, and is the easiest if you have it.
- Several phones now do a two-frame near-far blend automatically in macro mode.
The position
Focus stacking is not misrepresentation in most contexts. It produces an image of the subject as it is, with more of it in focus than one exposure could show, much as your eye does by refocusing as it scans.
Where it needs care is scientific and documentary work, where the convention is to disclose it, and competition entries, where rules vary and some categories prohibit any multi-frame technique. Natural history competitions in particular have differing rules on stacking, so check before entering rather than after.
And the real limit: stacking makes everything sharp, which is sometimes worse. Depth of field is a compositional tool: it separates subject from background and directs attention. A fully sharp macro photograph can look flat and clinical, like a specimen, because the visual hierarchy that focus provided has gone. Stack when the whole subject needs to be legible; do not stack by default.
Every lesson here is open. Your progress is recorded once you pass the Design, before Any Software exam.
Check your understanding
A macro photographer stacks 30 frames of a flower. The result is sharp throughout, but every stamen has a soft ghost outline around it. What causes this?
Pick the one you would defend. Your answer stays private.
Stuck on something?Ask Neema, your AI tutor
