app
Focus Stack
Focus Stack fuses at least two focal planes into one all-in-focus image using multilevel Laplacian focus evidence and exports a focus-depth index map.
Requirements And Launch
Inputs should show the same field of view at different focus positions.
labkit_FocusStack_app
Inputs
Add selected image files or choose a folder. Remove blurred, displaced, or otherwise invalid frames before running. The first image defines working geometry; differently sized inputs are resized and the result records how many images required resizing.
Basic Workflow
- Load at least two focal planes.
- Remove frames that do not belong to the stack.
- Start with the Balanced preset.
- Enable auto-registration when the stack has small rigid camera motion.
- Tune detail scale, blend radius, and uncertain blend only when artifacts are visible.
- Run the stack and inspect both fused image and focus map.
- Export fused PNG, focus-map PNG, and summary CSV.
Fusion Parameters
| Parameter | Default | Meaning |
|---|---|---|
| Preset | Balanced | coordinated starting values; Crisp favors fine detail, Smooth favors seam suppression, Noisy favors grain tolerance |
| Auto-register | off | register images to the middle image before fusion |
| Detail scale | 31 px | odd local window for focus-energy evidence |
| Blend radius | 4 px | smooth focus-selection weights across boundaries |
| Uncertain blend | 5% | blend competing planes where focus confidence is low |
The public calculation API also accepts minConfidence (default 0.05) and pyramidLevels (default 4, bounded by image geometry).
Algorithm
Images are normalized to grayscale or RGB double data on common geometry. A Gaussian/Laplacian pyramid is built for each plane. Local squared Laplacian detail energy chooses the strongest plane at each level. Confidence is the relative separation between the best and second-best evidence.
High-confidence regions use the winning plane. Low-confidence regions blend normalized evidence weights; zero-evidence regions use equal weights. The weights are spatially smoothed by the level-scaled blend radius and the fused pyramid is reconstructed and clamped to [0,1].
The focus index is the winning input plane at full resolution. Focus coverage is the fraction of pixels assigned to each plane. The algorithm does not correct parallax, deformation, moving objects, illumination changes, or severe registration error.
Outputs
- fused all-in-focus image;
- integer focus-depth index map;
- confidence map and per-plane focus coverage in the run result;
- summary CSV with geometry, parameters, confidence, coverage, registration, and resize information;
- result provenance manifest.
Use Without The GUI
images = {imread("z01.png"), imread("z02.png"), imread("z03.png")};
options = struct("focusWindow", 31, "smoothRadius", 4, ...
"minConfidence", 0.05, "pyramidLevels", 4);
result = focus_stack.analysisRun.computeFocusStack(images, options);
assert(result.ok, result.message);
imwrite(result.fused, "stacked.png");
Errors And Limitations
- Fewer than two images is an error.
- Reopening a saved stack is strict: an existing image that cannot be decoded aborts restore and leaves the current document unchanged.
minConfidencemust be finite and between 0 and 1.- Resizing changes sampling and should not substitute for consistent capture.
- Auto-registration should be reviewed; a wrong registration can create a sharp-looking but geometrically false composite.
Related Topics
Functions And API
Open a function for exact MATLAB syntax, arguments, outputs, behavior, and source.
| Function | Purpose |
|---|---|
focus_stack.analysisRun.computeFocusStack | Fuse a stack of images with different focus planes. |
Change history
- 2026-07-20 - App actions require explanatory hover helpfeat | compatible
- 2026-07-19 - App SDK explicit contract replaces the retired UI runtimerefactor | breaking
- 2026-07-17 - Project restore distinguishes missing sources from damaged sourcesfix | compatible
- 2026-07-17 - Explicit layout action contractrefactor | compatible
- 2026-07-16 - Image App project validation ownershiprefactor | compatible
- 2026-07-16 - Runtime-owned session defaults across App familiesrefactor | compatible
- 2026-07-16 - Focus Stack adopts the compact App contractrefactor | compatible
- 2026-07-16 - UI 7 public runtime boundaryrefactor | breaking
- 2026-07-15 - Runtime V2 lifecycle ownership across the app fleetrefactor | breaking
- 2026-07-13 - MATLAB-compatible image conversion APIrefactor | breaking
- 2026-07-13 - Base-MATLAB image compatibilityfeat | compatible
- 2026-07-09 - Default LabKit close protectionfix | compatible
- 2026-07-07 - Debug workflows, launcher tools, and changelog governancefeat | compatible
- 2026-07-06 - UI 5 facade redesign, app migration, and plot refreshrefactor | breaking
- 2026-07-03 - CSC export and viewport policyfeat | compatible
- 2026-07-03 - UI groups migrationrefactor | compatible
- 2026-07-03 - App file-selection and electrochem control fixesfix | compatible
- 2026-07-03 - Declarative app runtimerefactor | compatible
- 2026-07-01 - Debug sample packsfeat | compatible
- 2026-06-30 - Shared image facadefeat | compatible
- 2026-06-30 - App alerts through UI facadefeat | compatible
- 2026-06-30 - Close guards and caught-exception diagnosticsfeat | compatible
- 2026-06-30 - Output folder promptsfeat | compatible
- 2026-06-28 - App diagnostics and hardened UI workflowsfeat | compatible
- 2026-06-24 - File-panel migrationrefactor | breaking
- 2026-06-23 - Version metadata baselinefeat | compatible