← Engineering notebook
Optics & resolution

Focus stacking in production

High magnification destroys depth of field. Focus stacking is never purely an optical problem.

As magnification increases, depth of field disappears. There is no magic solution. You either accept blur, reduce throughput, or use computational techniques.

One focus position - only part of the scene is sharp
Focus position 1: only a narrow band is sharp; the rest is blurred.
A different focus position brings a different band into focus
Focus position 2: a different band is now sharp. Stacking keeps the sharp regions from each capture.

The problem

High magnification creates an extremely small depth of field, while real parts have:

  • Part warpage
  • Height variation
  • Focus drift over time

Approaches tried

  • Closing the aperture (loses light and resolution).
  • Increasing illumination (helps, but only so far).
  • Accepting blur (sometimes acceptable, often not).
  • Focus stacking - capture multiple images at different focus positions and combine the sharp regions into a single image.

Lessons learned

Focus stacking is never purely an imaging problem. Success depends on:

  • Stable mechanics
  • Precise, repeatable motion
  • Good software
  • Enough processing power and storage throughput

Most discussions focus only on optics. That is usually a mistake.