Focus stacking

On this page 7

Focus stacking is a capture and processing technique in photography that combines several exposures focused at different distances into one image whose sharp zone is deeper than any single frame could record. Within focus and autofocus, it is the standard answer when the required depth of field cannot be reached by stopping down the aperture without unacceptable diffraction softening.

The method is used most in macro, product and landscape work, where subjects are either very close to the lens or extend from the immediate foreground to the horizon. It trades a single click for a controlled sequence of frames and a merging step in software.

How focus stacking builds a deeper sharp zone

Focus stacking works because each frame contains a thin slice of acceptable sharpness, and software can identify which slice is sharpest at every pixel. The photographer shifts the focus plane in small steps through the subject, keeping exposure, framing and aperture constant, and the resulting sequence is merged into a composite with extended depth of field.

The merging software first aligns the frames, because changing focus slightly changes image magnification through focus breathing. It then measures local contrast in each frame, typically with edge or frequency-based operators, and builds a map that selects or weights the sharpest source for every region. Two families of algorithms dominate: depth-map methods, which pick one frame per pixel and preserve color and texture well, and pyramid methods, which blend contrast across scales and handle overlapping edges and fine hairs better but can raise contrast and shift colors.

The table below summarizes the stages of a typical stack and what can go wrong at each one.

StageWhat happensTypical failure
CaptureFocus moves in fixed steps from near to farGaps between sharp slices
AlignmentFrames are scaled, shifted and rotated to matchEdges smeared by poor registration
Sharpness mappingLocal contrast is measured for each frameNoise mistaken for detail
BlendingSharpest regions are combined into one imageHalos and transparent edges
RetouchingArtifacts are repaired from source framesInconsistent texture after cloning
Stages of a focus stack

Step size, frame count and aperture

The decisive capture parameter is the focus step, which must be smaller than the depth of field of one frame so that neighboring slices overlap. A common rule is to keep about 20 to 30 percent overlap between slices. Because depth of field shrinks dramatically with magnification, the number of frames needed ranges from a handful in landscapes to several hundred in high-magnification macro.

Aperture choice is a balance. Stopping down deepens each slice and reduces the frame count, but beyond a certain point diffraction lowers resolution across the whole image. Most practitioners therefore stack at the lens’s sharpest working aperture, often around f/5.6 to f/8 on full frame lenses, and accept more frames. At high magnification the effective aperture is larger than the marked value, so diffraction appears earlier.

Typical starting values differ widely by subject and magnification, as the following table shows.

SubjectMagnificationCommon apertureTypical frame count
LandscapeFar below 0.1xf/8 to f/112 to 5
Product tabletop0.1x to 0.5xf/8 to f/115 to 30
Close-up macro0.5x to 1xf/5.6 to f/820 to 80
Extreme macro2x to 5xf/2.8 to f/4 effective50 to 300 or more
Typical stacking parameters by subject

Methods of moving the focus plane

There are two ways to move the plane of focus through a subject: turning the focus ring or moving the whole camera on a rail. Many current cameras also offer in-camera focus bracketing, which drives the autofocus motor in programmed steps and records the sequence automatically.

The methods differ in precision, speed and perspective behavior, which matters most at high magnification.

MethodHow focus movesStrengthsLimitations
In-camera focus bracketingLens motor steps automaticallyFast, repeatable, no extra gearStep size set in abstract units
Manual focus ringPhotographer turns the ringWorks with any lensUneven steps, risk of camera movement
Macro focusing railCamera moves toward the subjectPrecise micrometer stepsChanges perspective slightly per frame
Motorized railController moves camera in set incrementsVery fine, consistent stepsSlow, costly, needs stable setup
Ways to shift focus for a stack

Focus ring stacking changes magnification between frames, while rail stacking changes perspective slightly. Both are correctable by alignment software, but rail stacking is preferred above about 2x magnification, where lens focusing ranges become too coarse or are already used up.

Focus stacking is one of several ways to control where sharpness falls, and it is easily confused with neighboring concepts. Unlike focus peaking, which only displays in-focus edges, it changes the final image. Unlike a tilt lens, which tilts the plane of focus to match a receding surface, it keeps the plane parallel to the sensor and adds planes instead.

ApproachPrincipleBest suited toMain drawback
Focus stackingMerges several focus distancesStatic macro and product subjectsMoving subjects create artifacts
Stopping downSmaller aperture deepens one frameModerate depth needsDiffraction and slower shutter
Hyperfocal focusingFocus set so infinity stays acceptableLandscapes with distant backgroundsNear foreground may stay soft
Tilt movementPlane of focus angled to the sceneFlat receding planesDoes not help tall subjects
Focus stacking and alternatives for depth

Stacking is also distinct from exposure bracketing for HDR, which varies brightness rather than focus. The two can be combined, but the frame count multiplies quickly.

Limitations and common artifacts

The central limitation of focus stacking is subject and camera stability. Any movement between frames, such as wind on a flower, an insect’s antenna or a vibrating tripod, produces ghosting and duplicated edges. For this reason live insect macro relies on fast handheld bursts with in-camera bracketing, while studio stacking uses electronic shutter, flash or a remote release.

  • Halos appear around high-contrast edges where a defocused foreground overlaps a sharp background.
  • Transparent regions form when thin structures such as hairs or bristles cross depth layers.
  • Banding of sharpness shows that the focus step was too large for the chosen aperture.
  • Shifting light during long outdoor sequences causes uneven brightness between slices.
  • Dust and noise are amplified because sharpness detection can treat them as detail.

Experienced practitioners shoot one extra frame beyond both ends of the subject, keep exposure and white balance in manual mode, and expect to retouch problem edges from individual source frames after the automatic merge.

Put simply

A camera can make only one distance perfectly sharp at a time. Everything nearer or farther looks softer. With a very close subject, such as a small bug or a ring, the sharp zone can be thinner than a sheet of paper.

Focus stacking solves this with many photos of the same scene. Each photo is focused a little further away, like slicing a loaf of bread. Software then keeps only the sharp part of every slice. It joins them into one picture that looks crisp from front to back.

In practice

A product photographer needs a wristwatch fully sharp from the front of the crown to the back of the strap for an online catalog. At about 0.3x magnification, a single frame at f/8 covers only a few millimeters of depth, and stopping down to f/22 would visibly soften the dial through diffraction.

The photographer locks the camera on a heavy tripod, sets exposure, white balance and flash power manually, and uses in-camera focus bracketing with 24 frames at f/8. The merging software aligns the sequence and produces a composite. A brief retouch fixes a small halo around the hands using one source frame, and the final image is sharp across the entire watch while keeping the lens at its best aperture.