Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Focus Stacking Workflow with focus-stack

A streamlined workflow and automation helper for focus stacking micro- and macro-photography using Petteri Aimonen's open-source tool focus-stack.

GitHub Repository


Overview

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-stack evaluates 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).

Repository Structure

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

Prerequisites & Installation

  1. Download focus-stack:
  2. Setup:
    • Place focus-stack.exe and its required DLL dependencies in your project root folder (or make sure focus-stack.exe is added to your system PATH).
    • Ensure the scripts in scripts/ and the workspace folder work/r are present.

Usage Workflow

The batch scripts automate execution without needing manual command-line entry:

  1. Clean Workspace: Run scripts/aaadel.cmd (or double-click it) to delete leftover source files and outputs from work/ and work/r/.
  2. Add Source Images: Copy your focus-bracketed images (.jpg or .tif) into the work/ folder.
  3. Run Focus Stacking:
    • For JPEG inputs: Run scripts/aaajpg.cmd
    • For TIFF inputs: Run scripts/aaatif.cmd
  4. Inspect & Post-Process:
    • The combined image is generated in work/r/output.jpg (along with a 3D depth preview 3dview.png).
    • Open and refine the result in Photoshop or your preferred photo editor.

Default CLI Parameters

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

Parameter Breakdown

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.

Practical Tips for Microscopy & Macro Stacking

  • 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.

Examples

Cross-section: Festuca rubra

Source Frames (40× Euromex Microscope Camera):

Euromex 56 Euromex 57 Euromex 58

Focus Stacking Result (work/r/output.jpg) → Post-Processed (work/r/output_1.jpg):

Raw Stacking Result Post-processed Result

Additional Sample Stacks

Butomus umbellatus Melica ciliata Rhytidiadelphus squarrosus
Butomus umbellatus Melica ciliata Rhytidiadelphus squarrosus

References & Credits

About

Using focus-stack by Petteri Aimonen (scripts, workflow, examples).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages