A streamlined workflow and automation helper for focus stacking micro- and macro-photography using Petteri Aimonen's open-source tool focus-stack.
Focus stacking is a digital image processing technique that combines multiple images captured at different focal planes to create a single composite image with extended depth of field (DoF):
- Extended Depth of Field: Keeps foreground and background elements sharp simultaneously, which is essential for high-magnification microscopy and close-up macro work.
- Wavelet-based Depth Mapping:
focus-stackevaluates sharpness across regions using wavelet transforms, builds a global depth map, and merges the sharpest areas into a seamless result. Image order does not matter. - Typical Workflow: Capture focus-bracketed source images → Merge using
focus-stack→ Post-process (e.g., contrast adjustment, tonal balance, dust removal in Photoshop or GIMP).
focus_stack/
├── samples/ # Example stacked results from botanical microscopy
│ ├── fr_1.jpg # Melica ciliata
│ ├── stqs_1.jpg # Butomus umbellatus
│ └── trb2_1.jpg # Rhytidiadelphus squarrosus
├── scripts/ # Helper batch scripts for automation
│ ├── aaadel.cmd # Clears the work/ workspace
│ ├── aaajpg.cmd # Executes stacking on work/*.jpg
│ └── aaatif.cmd # Executes stacking on work/*.tif
├── work/ # Working directory for current stacking job
│ ├── Euromex_56.jpg # Source input images (example set)
│ ├── Euromex_57.jpg
│ ├── Euromex_58.jpg
│ └── r/ # Output directory
│ ├── output.jpg # Raw merged output from focus-stack
│ └── output_1.jpg # Final post-processed image
├── focus_stack.md # Extended documentation & background notes (German)
└── readme.md # Project README
- Download
focus-stack:- Download the latest Windows binary release or build from source from the PetteriAimonen/focus-stack GitHub repository.
- Setup:
- Place
focus-stack.exeand its required DLL dependencies in your project root folder (or make surefocus-stack.exeis added to your systemPATH). - Ensure the scripts in
scripts/and the workspace folderwork/rare present.
- Place
The batch scripts automate execution without needing manual command-line entry:
- Clean Workspace:
Run
scripts/aaadel.cmd(or double-click it) to delete leftover source files and outputs fromwork/andwork/r/. - Add Source Images:
Copy your focus-bracketed images (
.jpgor.tif) into thework/folder. - Run Focus Stacking:
- For JPEG inputs: Run
scripts/aaajpg.cmd - For TIFF inputs: Run
scripts/aaatif.cmd
- For JPEG inputs: Run
- Inspect & Post-Process:
- The combined image is generated in
work/r/output.jpg(along with a 3D depth preview3dview.png). - Open and refine the result in Photoshop or your preferred photo editor.
- The combined image is generated in
The included batch scripts run focus-stack with tuned parameters suitable for microscope photography:
focus-stack.exe ^
--output=work/r/output.jpg ^
--no-whitebalance ^
--consistency=2 ^
--depthmap-threshold=110 ^
--halo-radius=20 ^
--verbose ^
--3dview=3dview.png ^
--denoise=2 ^
work/*.jpg| Flag | Description |
|---|---|
--output=work/r/output.jpg |
Target output path for the merged composite image. |
--no-whitebalance |
Disables automatic white balance adjustment across images to maintain uniform color consistency. |
--consistency=2 |
Consistency filter radius to mitigate misaligned pixels and stacking artifacts. |
--depthmap-threshold=110 |
Threshold for depth map segmentation, reducing noise in out-of-focus areas. |
--halo-radius=20 |
Radius for halo artifact reduction along high-contrast boundaries. |
--denoise=2 |
Applies wavelet-based noise suppression. |
--3dview=3dview.png |
Generates a 3D depth map visualization. |
--verbose |
Prints detailed diagnostic and progress output to stdout. |
- Optical Contrast: Keep optical contrast moderate during capture via the condenser aperture to reduce diffraction halos around high-contrast edges. Contrast can be boosted losslessly in post-processing.
- Stability: Ensure the specimen, stage, and camera remain completely still across the entire focus series.
Source Frames (40× Euromex Microscope Camera):
Focus Stacking Result (work/r/output.jpg) → Post-Processed (work/r/output_1.jpg):
| Butomus umbellatus | Melica ciliata | Rhytidiadelphus squarrosus |
|---|---|---|
![]() |
![]() |
![]() |







