{"course":{"slug":"image-editing","title":"Editing an Image","url":"https://addaly.com/learn/image-editing","level":"beginner","track":"create"},"lesson":{"slug":"focus-stacking","title":"When depth of field is not enough","url":"https://addaly.com/learn/image-editing/focus-stacking","position":57,"of":78,"minutes":8,"answer":"Focus stacking picks each pixel from the frame where local contrast is highest, so it needs frames whose sharp zones overlap and pixel-accurate alignment including the scale change from focus breathing.","keyIdea":"Focus stacking picks each pixel from the frame where local contrast is highest, so it needs frames whose sharp zones overlap and pixel-accurate alignment including the scale change from focus breathing; and it produces halos exactly where a sharp foreground edge meets a background sharp in a different frame."},"body":{"format":"markdown","text":"## The problem, with numbers\n\nDepth 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.\n\nThe 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.\n\n**Focus stacking** takes several frames at different focus distances and combines the sharp parts of each.\n\n## Shooting a stack\n\n- **Tripod, always.** The frames must align to the pixel.\n- **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.\n- **Do not change the aperture.** Depth of field must be consistent.\n- **Move the focus, not the camera**, unless you have a macro rail: moving the camera changes the composition and the perspective.\n- **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.\n- **Use a remote or the self-timer** so nothing shifts between frames.\n\n## Focus breathing, and why alignment is not optional\n\nAs 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.\n\nThat 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.\n\n```bash\nalign_image_stack -m -a aligned_ -v *.tif\nenfuse --exposure-weight=0 --saturation-weight=0 --contrast-weight=1 \\\n       --hard-mask -o stacked.tif aligned_*.tif\n```\n\nThe `-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.\n\n## How the combination works, and where it goes wrong\n\nThe 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.\n\nThe 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.\n\nThis is most visible on:\n\n- 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.\n- Objects against a bright background, where the out-of-focus version of the object was larger and lighter.\n\nThe 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.\n\n## Movement kills it\n\nAnything 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:\n\n- Work indoors, or on a still day, or shield the subject.\n- Shoot the stack as fast as the equipment allows.\n- 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.\n\n## Free software\n\n- **Hugin's align_image_stack + enfuse**, as above. Free, scriptable, excellent.\n- **darktable** can align and blend, though it is not its primary purpose.\n- **GIMP** with the G'MIC plugin has a focus-stacking filter.\n- **Photoshop** does it with Auto-Align plus Auto-Blend, and is the easiest if you have it.\n- Several phones now do a two-frame near-far blend automatically in macro mode.\n\n## The position\n\nFocus 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.\n\nWhere 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.\n\nAnd 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."},"check":{"question":"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?","options":[{"text":"The focus steps were too large, so the sharp zones did not overlap and a band of softness fell across the stamens.","correct":false,"tempting":"Names a real stacking error whose symptom is a zone of softness at a particular depth rather than a halo tracing every thin object's outline."},{"text":"The alignment did not correct for focus breathing, so the frames are at slightly different magnifications and thin structures are doubled.","correct":false,"tempting":"Identifies a genuine requirement whose failure produces progressive misregistration across the whole frame, worst at the edges rather than on the thinnest subjects."},{"text":"In the frames where a stamen is out of focus its blurred image is wider than its sharp one, so the surrounding blur is still the highest-contrast content in that region and survives the selection.","correct":true},{"text":"The blending used exposure weighting rather than contrast weighting, so brightness rather than sharpness decided which frame won at each pixel.","correct":false,"tempting":"Describes a genuine settings mistake that would produce a muddled, low-contrast composite rather than a sharp image with a consistent halo on thin structures."}]},"prev":{"slug":"panoramas-and-stitching","title":"Many frames, one view, and the pivot point that matters","url":"https://addaly.com/learn/image-editing/panoramas-and-stitching"},"next":{"slug":"matching-grain-noise-and-focus","title":"The last tell: texture and depth","url":"https://addaly.com/learn/image-editing/matching-grain-noise-and-focus"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Exam keys checked blind by a second model: 3,665 of 3,666 agreed. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 'When depth of field is not enough', in Editing an Image. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/image-editing/focus-stacking (Accessed: 13 October 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"When depth of field is not enough","courseTitle":"Editing an Image","module":{"index":6,"slug":"compositing","title":"Compositing: making two pictures one"},"answer":null,"keyIdea":"Focus stacking picks each pixel from the frame where local contrast is highest, so it needs frames whose sharp zones overlap and pixel-accurate alignment including the scale change from focus breathing; and it produces halos exactly where a sharp foreground edge meets a background sharp in a different frame.","hero":{"kind":"plate","image":null,"alt":null,"caption":null},"blocks":[{"t":"h2","id":"the-problem-with-numbers","runs":[{"text":"The problem, with numbers"}]},{"t":"p","runs":[{"text":"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."}]},{"t":"p","runs":[{"text":"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."}]},{"t":"p","runs":[{"text":"Focus stacking","b":true},{"text":" takes several frames at different focus distances and combines the sharp parts of each."}]},{"t":"h2","id":"shooting-a-stack","runs":[{"text":"Shooting a stack"}]},{"t":"ul","items":[[{"text":"Tripod, always.","b":true},{"text":" The frames must align to the pixel."}],[{"text":"Manual focus, moved in small steps","b":true},{"text":" 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."}],[{"text":"Do not change the aperture.","b":true},{"text":" Depth of field must be consistent."}],[{"text":"Move the focus, not the camera","b":true},{"text":", unless you have a macro rail: moving the camera changes the composition and the perspective."}],[{"text":"How many frames:","b":true},{"text":" 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."}],[{"text":"Use a remote or the self-timer","b":true},{"text":" so nothing shifts between frames."}]]},{"t":"h2","id":"focus-breathing-and-why-alignment-is-not-optional","runs":[{"text":"Focus breathing, and why alignment is not optional"}]},{"t":"p","runs":[{"text":"As the lens refocuses, its effective focal length changes slightly. The frame therefore "},{"text":"changes magnification","b":true},{"text":" across the stack, a phenomenon called focus breathing, so the last frame is slightly more or less magnified than the first."}]},{"t":"p","runs":[{"text":"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."}]},{"t":"code","lang":"bash","label":"Bash","text":"align_image_stack -m -a aligned_ -v *.tif\nenfuse --exposure-weight=0 --saturation-weight=0 --contrast-weight=1 \\\n       --hard-mask -o stacked.tif aligned_*.tif"},{"t":"p","runs":[{"text":"The "},{"text":"-m","code":true},{"text":" 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."}]},{"t":"h2","id":"how-the-combination-works-and-where-it-goes-wrong","runs":[{"text":"How the combination works, and where it goes wrong"}]},{"t":"p","runs":[{"text":"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."}]},{"t":"p","runs":[{"text":"The failure follows directly from that. "},{"text":"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.","b":true},{"text":" What you get is a halo: a ring of blurred or doubled detail tracing the foreground object’s outline."}]},{"t":"p","runs":[{"text":"This is most visible on:"}]},{"t":"ul","items":[[{"text":"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."}],[{"text":"Objects against a bright background, where the out-of-focus version of the object was larger and lighter."}]]},{"t":"p","runs":[{"text":"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 "},{"text":"Edit > Auto-Blend Layers","i":true},{"text":" with "},{"text":"Stack Images","i":true},{"text":" does a reasonable job and leaves the masks editable, which is its main advantage over a command-line tool."}]},{"t":"h2","id":"movement-kills-it","runs":[{"text":"Movement kills it"}]},{"t":"p","runs":[{"text":"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:"}]},{"t":"ul","items":[[{"text":"Work indoors, or on a still day, or shield the subject."}],[{"text":"Shoot the stack as fast as the equipment allows."}],[{"text":"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."}]]},{"t":"h2","id":"free-software","runs":[{"text":"Free software"}]},{"t":"ul","items":[[{"text":"Hugin’s align_image_stack + enfuse","b":true},{"text":", as above. Free, scriptable, excellent."}],[{"text":"darktable","b":true},{"text":" can align and blend, though it is not its primary purpose."}],[{"text":"GIMP","b":true},{"text":" with the G’MIC plugin has a focus-stacking filter."}],[{"text":"Photoshop","b":true},{"text":" does it with Auto-Align plus Auto-Blend, and is the easiest if you have it."}],[{"text":"Several phones now do a two-frame near-far blend automatically in macro mode."}]]},{"t":"h2","id":"the-position","runs":[{"text":"The position"}]},{"t":"p","runs":[{"text":"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."}]},{"t":"p","runs":[{"text":"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."}]},{"t":"p","runs":[{"text":"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."}]}],"check":{"question":[{"text":"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?"}],"options":[{"text":[{"text":"The focus steps were too large, so the sharp zones did not overlap and a band of softness fell across the stamens."}],"correct":false,"tempting":[{"text":"Names a real stacking error whose symptom is a zone of softness at a particular depth rather than a halo tracing every thin object’s outline."}]},{"text":[{"text":"The alignment did not correct for focus breathing, so the frames are at slightly different magnifications and thin structures are doubled."}],"correct":false,"tempting":[{"text":"Identifies a genuine requirement whose failure produces progressive misregistration across the whole frame, worst at the edges rather than on the thinnest subjects."}]},{"text":[{"text":"In the frames where a stamen is out of focus its blurred image is wider than its sharp one, so the surrounding blur is still the highest-contrast content in that region and survives the selection."}],"correct":true,"tempting":null},{"text":[{"text":"The blending used exposure weighting rather than contrast weighting, so brightness rather than sharpness decided which frame won at each pixel."}],"correct":false,"tempting":[{"text":"Describes a genuine settings mistake that would produce a muddled, low-contrast composite rather than a sharp image with a consistent halo on thin structures."}]}],"order":[1,0,3,2],"why":null},"prev":{"slug":"panoramas-and-stitching","title":"Many frames, one view, and the pivot point that matters","minutes":9},"next":{"slug":"matching-grain-noise-and-focus","title":"The last tell: texture and depth","minutes":8}}}