← All projects

Focus Stacking & Mosaic

CLI and GUI app to focus-stack z-slices and stitch tiles into mosaics with exposure and flat-field correction.

Focus Stacking & Mosaic

Overview

A Python 3.11+ application (CLI + GUI) that focus-stacks sets of z-slices per XY position and stitches the stacked tiles into a uniform mosaic, with exposure compensation and flat-field correction.

What it does

  • Focus-stack z-slices per position using Laplacian-pyramid fusion with Tenengrad weights.
  • Export the stacked image plus a focus map, depth map, QC preview and metadata.
  • Stitch stacked tiles into a grid mosaic with per-tile exposure compensation, cosine-weighted blending, and global flat-field correction.
  • Preserves 16-bit input in output TIFFs; optional ECC/ORB alignment for XY jitter.

Outputs per position

output/<position_id>/
  <position_id>_STACKED.tif
  <position_id>_FOCUSMAP.tif
  <position_id>_DEPTHMAP.tif
  <position_id>_QC.png
  meta.json

CLI example

python focus_app.py stack \
  --input "/data/run01" --pattern "*.jpg" --output "/data/run01_out" \
  --focus-method pyramid --pyramid-scales 4 --save-depth True --save-focus True

python focus_app.py stitch \
  --input "/data/run01_out" --pattern "*_STACKED.tif" --output "/data/mosaic" \
  --grid-rows 17 --grid-cols 1 --overlap-x 0.10 --overlap-y 0.10

The GUI offers the same workflow across Stack and Stitch tabs (manual file selection or automatic grouping by filename), and can be packaged into a single standalone Windows .exe with PyInstaller.