5 min read

Focus Stacking: When Depth of Field Isn't Enough

Some subjects have more depth than any single aperture can cover. Focus stacking is the answer: shoot several frames focused at different distances, then blend them so each part of the final image comes from the frame where it was sharpest. It gives front-to-back sharpness that physics will not give in one exposure.

When you need it

Most photography never does. It becomes necessary in two places. The first is macro. Depth of field at close range is tiny, and it shrinks roughly with the square of the magnification. On full frame, using the standard circle of confusion, the whole zone in focus at 1:1 is about 0.65 mm at f/5.6, 0.9 mm at f/8, 1.3 mm at f/11 and 1.9 mm at f/16. At half life size it is about 1.9, 2.8, 3.8 and 5.5 mm, and at 2:1 only 0.24, 0.35, 0.48 and 0.69 mm. A coin, a stamen or an insect's head has more depth than that.

The second is landscape or architecture with something very close. At 24 mm and f/16, the nearest sharp distance with the horizon still sharp is about 0.64 m, so a rock or flower at 30 cm cannot be covered in a single frame at any aperture, as the landscape aperture post shows. Two or three frames solve it.

Why not just stop down?

Because the aperture you set is not the aperture you get at close range. The effective f-number is the marked one multiplied by one plus the magnification, so at 1:1 an f/8 setting behaves like f/16. On a 45 MP sensor, the diffraction disc at f/16 is about 4.9 pixels across, against 3.4 pixels at an effective f/11 (marked f/5.6). So stacking at f/5.6 to f/8 and using more frames beats a single frame at f/16 or f/22. The diffraction post has the numbers.

How many frames?

Divide the subject's depth by the depth of field per frame, after allowing about 30 percent overlap between neighbouring frames. The answer depends heavily on how strict you are about sharpness. Take a subject 6 mm deep at 1:1 and f/8. With the standard circle of confusion, each frame covers 0.92 mm, and with overlap the step is about 0.65 mm, so you need about 10 frames. If you want pixel-level sharpness on a 45 MP sensor, each frame covers only about 0.28 mm, the step is about 0.2 mm, and you need about 30. At 2:1 with the same strictness it climbs to about 80. A flower 20 mm deep at half life size needs about 11 frames at the standard value. So treat any table of frame counts as a guide, and test your own setup.

Shooting a stack

Put the camera on a tripod, since every frame needs to line up except for the focus. Use a remote release or a short self-timer, and an electronic or electronic-first-curtain shutter to avoid vibration. Set exposure manually so brightness does not change between frames, and use f/5.6 to f/8 for most macro work. Find the nearest and farthest parts you want sharp, and shoot from one to the other in small steps. Keep the subject and the light still. Moving air and live subjects are the enemies of a clean stack, and continuous lighting avoids the colour shifts some flash units show.

Moving the focus

You can turn the focus ring by hand, which is slow and imprecise. A macro rail moves the whole camera in fixed steps, which is repeatable and also avoids focus breathing, where a lens changes its magnification as it focuses. Or you can use in-camera focus bracketing, which many recent Canon, Nikon, Sony, Fujifilm, OM System and Panasonic cameras offer. You set the number of frames and a step size, and the camera shoots the sequence. Step sizes are usually on an arbitrary scale, so shoot a test stack, and if you see soft gaps between sharp zones, use a smaller step and more frames.

Blending

Photoshop does it with Auto-Align Layers followed by Auto-Blend Layers set to Stack Images, and works well for modest stacks of about 5 to 15 frames. Helicon Focus is the dedicated tool for serious work, with three methods: A (weighted average), B (depth map), which is a good default, and C (pyramid), which suits fine texture but can show halos. Zerene Stacker is favoured for translucent or fine structures such as insect wings, with its PMax and DMap methods and manual retouching. Free and low-cost options exist, such as CombineZP and Affinity Photo's focus merge.

Common problems are soft gaps (use more frames), halos around edges (change the blending method or radius), ghosting where something moved (shoot faster and mask by hand), colour shifts (use constant light and fix white balance first), and misalignment (use a heavier tripod and let the software auto-align).

Landscape stacking

It is simpler. Take one frame focused on the nearest element, often 30 to 80 cm away, another at the hyperfocal distance or beyond for the background, and a third in the middle if there is a big gap. Blend them in Photoshop or with a layer mask. Moving vegetation between frames makes ghosting that is hard to repair, so shoot when the air is still, usually early in the day.

When not to stack

Not with moving subjects such as wildlife, water or people. Not handheld, since the misalignment is usually too large. Not when shallow focus is the point of the picture, because stacking removes the blur. And not when a single frame at f/8 to f/11 already works. Tilt can help for a subject with a flat surface, as in the tilt-shift post.

To work out how much depth each frame covers for your lens and distance, use the calculator.

Related reading: Best Aperture for Landscape Photography, Mirrorless vs DSLR: Does It Affect DOF?, Night Photography: DOF at High ISO.