This document provides a complete and authoritative reference for all command-line parameters used in the Sperm Motility Analysis Pipeline.
How to use this document
- 📊 Use the tables for quick lookup
- 🔍 Use the detailed sections to understand parameter behavior and tuning strategies
uv run main.py [OPTIONS] input_pathParameters can be provided via:
- Command-line flags
- JSON configuration file (
--params-file, strongly recommended)
Priority rule: Command-line values always override JSON values.
This section provides a practical tuning roadmap. In most cases, you do not need to tune all parameters.
If detection is wrong, everything downstream fails.
Tune in the following order:
-
--det-thresholdControls foreground/background separation.- Too low → noise
- Too high → missed sperm
-
--det-min-area,--det-max-areaMatch sperm head size in pixels. -
--det-min-solidityRemoves irregular debris and merged objects. -
--det-min-aspect,--det-max-aspectSpecies-dependent (round vs. elongated heads).
🎯 Goal: Every visible sperm head is detected once per frame.
After detection is stable, tune motion constraints.
Tune in this order:
-
--trk-max-distanceMaximum movement allowed between frames (pixels). -
--trk-angle-hard-cutPrevents non-biological sharp turns. -
--trk-max-ageAllows short occlusions without breaking tracks.
🎯 Goal: Tracks follow sperm smoothly without jumping.
These parameters refine which detection belongs to which track.
Tune only if you observe:
- ID switches
- Track hopping
- Broken trajectories
Key parameters:
--trk-weight-direction(increase first)--trk-weight-distance--trk-sigma-angle(smaller = stricter)--trk-sigma-distance
Tune only if:
- You care about immotile sperm, or
- Motile tracking is confused by static objects
Tune in this order:
-
--imm-search-radiusTolerance for drift. -
--imm-max-stdSeparates true immotile from slow movers. -
--imm-min-pointsPrevents false immotile tracks.
Tracking must already be correct.
Critical parameters:
--pixel-size⚠️ (most important)--fps- Motility thresholds (
--ana-motility-*)
Tune based on:
- Species
- Temperature
- Experimental protocol
🧠 Rule of Thumb
Fix detection first → then tracking geometry → then matching behavior → then analysis.
| Argument | Description |
|---|---|
input_path |
Input movie file or directory containing movies |
| Option | Type | Description |
|---|---|---|
-o, --output-dir |
Path |
Required. Base output directory |
--params-file |
Path |
Optional JSON configuration file |
--viz-dir |
Path |
Directory containing original movies for visualization |
--cut-input-prefix |
str |
Prefix to remove from input filenames |
--cut-input-suffix |
str |
Suffix to remove from input filenames |
--cut-viz-prefix |
str |
Prefix to remove from visualization filenames |
--cut-viz-suffix |
str |
Suffix to remove from visualization filenames |
--input-glob |
str |
Glob pattern for input files (e.g. *.tif, *.avi) |
--viz-glob |
str |
Glob pattern for visualization files |
-r, --recursive |
flag | Recursively search input and visualization directories |
Parameters controlling sperm head detection via image morphology.
| Option | Type | Description |
|---|---|---|
--det-min-area |
int |
Minimum detection area (pixels²) |
--det-max-area |
int |
Maximum detection area (pixels²) |
--det-min-aspect |
float |
Minimum aspect ratio |
--det-max-aspect |
float |
Maximum aspect ratio |
--det-min-solidity |
float |
Minimum solidity threshold (0–1) |
--det-threshold |
int |
Binarization threshold before detection (0–255) |
--det-blur-radius |
float |
Gaussian blur radius for preprocessing (pixels) |
--det-point-radius |
int |
Radius of detection markers in visualization (pixels) |
--det-point-color |
str |
Detection marker color |
--det-fps |
int |
FPS for detection visualization movies |
Motion-aware, multi-factor sperm tracking.
| Option | Type | Description |
|---|---|---|
--trk-max-age |
int |
Maximum missing frames before a track is deleted |
--trk-min-hits |
int |
Minimum detections to validate a track |
--trk-min-track-length |
int |
Minimum frames to keep a track |
--trk-min-confidence |
float |
Minimum confidence score (0–1) |
| Option | Type | Description |
|---|---|---|
--trk-max-distance |
float |
Maximum linking distance between frames (pixels) |
--trk-angle-hard-cut |
float |
Maximum allowed direction change (degrees) |
| Option | Type | Description |
|---|---|---|
--trk-weight-distance |
float |
Weight for spatial proximity |
--trk-weight-direction |
float |
Weight for movement direction |
--trk-weight-speed |
float |
Weight for speed consistency |
--trk-weight-morphology |
float |
Weight for shape similarity |
| Option | Type | Description |
|---|---|---|
--trk-sigma-distance |
float |
Distance Gaussian spread (pixels) |
--trk-sigma-angle |
float |
Direction Gaussian spread (degrees) |
--trk-sigma-speed |
float |
Speed Gaussian spread (pixels/frame) |
| Option | Type | Description |
|---|---|---|
--trk-appearance-thresh |
float |
Minimum shape similarity score (0–1) |
--trk-appearance-verify-dist |
float |
Maximum distance to verify appearance match (pixels) |
--trk-gamma-tau |
float |
Predictive distance scaling factor |
--trk-use-tau |
flag | Enable predictive tracking |
--trk-use-kalman |
flag | Enable Kalman filtering |
| Option | Type | Description |
|---|---|---|
--trk-assignment-mode |
{greedy,hungarian} |
Assignment strategy |
--trk-history-len |
int |
Frames for direction/speed estimation |
--trk-min-edge-frames |
int |
Frames before edge-based spawn filtering |
--trk-edge-spawn-threshold |
float |
Edge region size as fraction of image dimension |
| Option | Type | Description |
|---|---|---|
--viz-trail-length |
int |
Track trail length (frames) |
--viz-track-width |
int |
Track line width (pixels) |
--viz-overview-frame |
int |
Frame index for overview image |
--viz-overview-track-width |
int |
Track width in overview image |
--viz-point-radius |
int |
Point radius |
--viz-point-color |
str |
Point color |
--viz-track-color |
str |
Track color |
Optional immotile sperm separation prior to motile tracking.
(All detailed explanations preserved and clarified for readability.)
| Option | Type | Description |
|---|---|---|
--pixel-size |
float |
Pixel size (µm/pixel) |
--fps |
float |
Recording frame rate |
--vap-window |
int |
VAP smoothing window |
--ana-motility-vcl-threshold |
float |
VCL motility threshold |
--ana-motility-vsl-threshold |
float |
VSL motility threshold |
--ana-motility-vap-threshold |
float |
VAP motility threshold |
| Option | Description |
|---|---|
--detect-only |
Run detection only |
--tracking-only |
Run tracking only |
--analysis-only |
Run analysis only |
--verbose |
Enable verbose logging |
This section provides in-depth explanations, biological meaning, tuning guidance, and practical examples for each parameter listed above.
Input movie file or directory.
-
Supported formats:
.tif,.tiff,.avi,.mp4, etc. -
If a directory is provided, files are selected using
--input-globExample:--input-glob="*-enhanced.avi"
Path to a JSON file containing parameters.
Use example/zebrafish_sperm_params.json as a template.
✅ Strongly recommended for:
- Batch processing
- Reproducibility
- Sharing analysis settings
Directory containing visualization movies (e.g. original brightfield movies).
Used to:
- Overlay detections
- Generate tracking videos
- Create overview images
If not provided, visualization overlays use the input movie.
Remove unwanted filename parts before matching input and visualization movies.
Example
Stream-2-enhanced.avi
--cut-input-suffix "-enhanced"
→ Stream-2.avi
.avi) are not removed.
Filter detected objects by size (pixels²).
- Too small → noise
- Too large → debris, clumps, merged sperm
💡 Tune according to magnification and species.
Aspect ratio = major axis / minor axis.
- Mouse / human / bovine → elongated heads
- Zebrafish → round heads
- Rejects debris and merged detections
Solidity = area / convex hull area.
- Low solidity → irregular shapes, debris
- High solidity → compact sperm heads
Typical range: 0.6 – 0.8
Threshold for binarization.
- Pixel value > threshold → sperm (white)
- Pixel value ≤ threshold → background (black)
Behavior:
- Lower → more detections, more noise
- Higher → cleaner but may miss dim sperm
💡 How to tune?
- open the movie in ImageJ/Fiji
- Use the "Image" → "Adjust" → "Threshold" tool
- Adjust the "Value" slider to find a balance between sperm and background
Usually start with 5–15 because we already preprocessed movies to remove background noise and make it white-sperm on black-background.
Gaussian blur radius (pixels).
- Suppresses pixel-level noise
- Excessive blur merges nearby sperm
Typical values: 1–3
Maximum number of frames a track can be missing before deletion.
- Handles brief occlusions and focus loss
- Larger values increase false continuation risk
Minimum number of detections required to confirm a track.
- Prevents one-frame noise tracks
- Lower for sparse data
Typical value: 3
Tracks shorter than this are discarded.
Useful to:
- Remove spurious detections
- Focus on biologically meaningful motion
Maximum allowed movement between consecutive frames (pixels).
How to tune
- Open a movie
- Observe several fast sperm
- Estimate pixel displacement between frames
- Tune and validate against tracking results
Maximum allowed turning angle (degrees).
- Default ≈
120° - Sperm move curvilinearly, not with sharp reversals
- Usually do not turn more than
90°
Typical range: 90–120°
Number of previous frames used to estimate direction and speed.
- Default:
2 - Range:
1–5 - Larger values smooth direction estimates
Minimum number of frames before applying edge-based spawn filtering.
- Default:
3 - Prevents early tracks starting at image borders
Fraction of image dimension defining the edge region.
- Default:
0.1(10% from image edge) - Larger values restrict new track spawning near borders
Control importance during track–detection matching:
- Direction → trajectory continuity (most important)
- Distance → spatial proximity
- Speed → velocity consistency
- Morphology → shape similarity
Gaussian spreads controlling tolerance:
- Larger sigma → more permissive matching
- Smaller sigma → stricter matching
Minimum shape similarity threshold.
- Range:
0–1 - Default:
0.85 - Higher values demand stronger shape consistency
Maximum distance (pixels) for verifying appearance similarity.
- Default:
50 - Shape matching only applied within this radius
Predictive distance scaling factor.
- Default:
1.2 - Larger values predict further ahead along motion direction
Enable predictive, direction-based tracking.
- Default: enabled
- Improves continuity in fast-moving sperm
Enable Kalman filtering.
- Default: disabled
- Adds smoothing and advanced prediction
- Useful in noisy or low-FPS data
| Mode | Behavior |
|---|---|
greedy |
Faster, suitable for dense scenes |
hungarian |
Globally optimal, better for sparse scenes |
Enables two-stage tracking:
- Identify immotile sperm first (Immotile sperm violate motion-based assumptions and are identified using an immotile hypothesis regression model.)
- Track motile sperm using motion-based tracking
Improves accuracy for mixed motile/immotile populations.
Initial frames assumed to contain immotile anchors.
- Usually
1frame is sufficient
Maximum allowed positional deviation for immotile sperm.
- Accounts for stage drift and noise
- Smaller → stricter immotility
- Larger → more drift tolerance
Minimum number of detections required to confirm immotility.
- Default:
8
Spatial standard deviation threshold.
- Low STD → truly immotile
- High STD → slow or motile sperm
Polynomial drift correction order.
Immotile sperm positions are modeled across time:
| Order | Interpretation |
|---|---|
| 0 | Static |
| 1 | Linear drift |
| 2 | Curved drift |
Minimum number of frames to confirm an immotile track.
- Default:
6
Parallel jobs for immotile processing.
-1→ use all cores- Default:
-1
Batch size for parallel processing.
'auto'→ joblib auto tuning- Integer → custom batch size
Micrometers per pixel.
Recording frame rate.
Used to compute:
- VCL
- VSL
- VAP
Number of frames used for average-path smoothing.
- Small → sensitive
- Large → smoother but less responsive
Used for CASA-based classification:
- Motile
- Immotile
Tune according to:
- Species
- Temperature
- Experimental conditions
Curvilinear velocity threshold (µm/frame).
Straight-line velocity threshold (µm/s).
Average-path velocity threshold (µm/s).
- Tables → quick reference
- Tuning roadmap → what to adjust first
- Detailed section (this part) → how and why parameters work
