An automated, modular Fiji/ImageJ macro for batch Z-stack focus profiling and optimal slice range selection across multi-channel 3D microscopy datasets. Supports all major vendor formats (.oif, .nd2, .czi, .tif, .lif, etc.) and handles any number of image channels (
To run this macro, you will need:
- Fiji (ImageJ) (version 1.54 or later recommended).
- Bio-Formats Plugin: Required to open proprietary microscopy stack formats (
.oif,.nd2,.czi,.lif, etc.).
-
Multi-Format Support: Select specific proprietary file extensions (
.oif,.nd2,.czi,.tif,.lif,.lsm) or process all supported formats in a folder. -
Dynamic
$N$ -Channel Processing: Automatically detects channel count (1, 2, 3, 4+ channels) and appends individual metrics per channel to the final report. -
Dual Analysis Modes:
-
Dynamic Threshold Mode: Calculates signal bounds based on a relative threshold above background noise:
$$\text{Threshold} = \text{Min} + \text{Cutoff} \times (\text{Max} - \text{Min})$$ -
Fixed Sliding Window Mode: Identifies the optimal subset of
$N$ contiguous slices maximizing cumulative edge focus score.
-
Dynamic Threshold Mode: Calculates signal bounds based on a relative threshold above background noise:
-
Interactive GUI Dialog: Configure parameters (extensions, threshold %, window size, padding, CSV auto-save) at launch without editing code.
-
Headless Memory Optimization: Auto-clears buffer images to ensure crash-free execution on large batch datasets.
- Open Fiji/ImageJ.
- Drag and drop
Universal_Z_Stack_Profiler.ijminto Fiji, or add it at the end of theFiji.app/macros/StartupMacros.fiji.ijmfile. - Click Run.
- Configure your analysis parameters in the setup dialog.
- Select the directory containing your 3D stack images.
Upon execution, the macro generates:
-
Results Table & Auto-Saved CSV: An interactive ImageJ table (and
.csvfile if enabled) listing peak Z-slices ($Z_{peak}$ ) and optimal slice counts for every channel of each file. - Frequency Distribution Histograms: A standalone bar chart per channel (C1, C2, ..., Cn) visualizing the distribution of optimal slice counts across the entire batch.
- Global Summary Statistics: The ideal mean number of slices printed to the Log window per channel with total batch counts.
This project is licensed under the MIT License - see the LICENSE file for details.
