tezvyn:

How does focus stacking build an all-in-focus image?

AI-drafted, machine-checkedSource: interviewadvanced
WHAT IT TESTS

extended depth of field via focus stacking.

OUTLINE

align frames, measure local sharpness as a focus metric, select or blend the sharpest source per region, then composite.

WHAT THIS TESTS The interviewer wants a concrete fusion algorithm and, crucially, how you define and measure local focus.

A GOOD ANSWER COVERS The input is a focal stack: the same scene shot while sweeping the focus plane, so different depths are sharp in different frames. Step one is alignment; refocusing slightly changes magnification and viewpoint, so frames must be registered, often with a similarity or homography warp, or they will not composite cleanly. Step two is measuring focus locally: in-focus regions have high local contrast and high-frequency content, so you compute a focus metric per pixel or patch, such as the variance of the Laplacian, the local gradient magnitude, or energy in high-frequency wavelet bands. Step three is selection or blending: for each region pick the source frame with the maximum focus measure, building a selection map, or blend frames with weights proportional to their sharpness. Step four cleans up: regularize the selection map to avoid speckle, and blend across boundaries, for example with a Laplacian pyramid, so transitions between source images are seamless.

COMMON WRONG ANSWERS Skipping alignment, ignoring focus-induced magnification change. Using a single global focus metric instead of a per-region one. Hard-switching between sources with no boundary blending, leaving visible seams.

LIKELY FOLLOW-UPS Which focus measure is most robust to noise, handling halos at depth discontinuities, comparison with depth-from-focus, and microscopy or macro use cases.

ONE CONCRETE EXAMPLE For a macro shot of an insect where only the eye is sharp in one frame and the legs in another, you align the stack, compute Laplacian variance per patch, assign each patch to the sharpest frame, smooth the resulting map, and pyramid-blend the seams to produce one crisp insect fully in focus.

Read the original → en.wikipedia.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.