Skip to content

Commit 4cafecd

Browse files
Add supervised WMH module: LST-AI + FreeSurfer SAMSEG (#113)
New self-contained, sourceable module src/modules/wmh_lst_samseg.sh adding pretrained, training-data-free white-matter-hyperintensity (WMH) detection: - run_lstai_wmh: LST-AI (deep-learning SPM-LST successor; pip/Docker, no MATLAB). Detects CLI / importable lst_ai module (via uv) / Docker image; runs on FLAIR+T1; produces lesion mask + probability map + volume. - run_samseg_wmh: FreeSurfer SAMSEG (run_samseg --lesion --lesion-mask-pattern "0 1" -i T1 -i FLAIR); extracts lesion label 99 -> binary mask + volume. - run_supervised_wmh_lst_samseg: dispatcher running whichever tools are enabled + available. Both back-ends additionally intersect the whole-brain lesion mask with the pipeline's brainstem mask (safe_fslmaths) and report brainstem-restricted WMH separately, with a machine-readable summary per tool. All paths degrade gracefully (WARNING + return 0) when a tool is disabled/absent/fails, so they never abort the pipeline. The module follows the sourced-module convention (include guard, source require_env.sh, no top -level set -e to avoid leaking shell options into the parent) and uses log_* / safe_fslmaths / fslstats idioms. config/default_config.sh: add WMH_LSTAI_ENABLED/WMH_SAMSEG_ENABLED (both default false), LSTAI_THRESHOLD/DEVICE/DOCKER_IMAGE, SAMSEG_LESION_THRESHOLD (0.3), SAMSEG_LESION_MASK_PATTERN/LABEL/EXTRA_OPTS. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 05adf30 commit 4cafecd

2 files changed

Lines changed: 533 additions & 0 deletions

File tree

config/default_config.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,34 @@ export GMM_FALLBACK_PERCENTILE=97.5 # --fallback-percentile: used when GMM f
244244
# It defaults to THRESHOLD_WM_SD_MULTIPLIER (above) so there is ONE
245245
# authoritative fallback value. Override only if you need them to diverge.
246246

247+
# ---------------------------------------------------------------------------
248+
# Supervised / learned WMH detection (LST-AI + FreeSurfer SAMSEG)
249+
# ---------------------------------------------------------------------------
250+
# Optional, pretrained, training-data-free WMH/lesion segmentation back-ends
251+
# implemented in src/modules/wmh_lst_samseg.sh. Both are OFF by default and
252+
# require external tools that are NOT part of the core pipeline dependency set:
253+
# - LST-AI : deep-learning successor to SPM-LST. Install via 'pip install
254+
# lst-ai' (Python, no MATLAB) or pull the Docker image. Needs
255+
# co-registered FLAIR + T1; ships pretrained weights.
256+
# - SAMSEG : FreeSurfer >=7.x 'run_samseg --lesion' (needs $FREESURFER_HOME).
257+
# Synergizes with the FreeSurfer brainstem segmentation added in a
258+
# sibling unit (shared FreeSurfer install + brainstem labels).
259+
# Each back-end intersects its whole-brain lesion mask with the pipeline's
260+
# brainstem mask to report a brainstem-restricted WMH burden separately.
261+
export WMH_LSTAI_ENABLED=false # true => run LST-AI when available
262+
export WMH_SAMSEG_ENABLED=false # true => run FreeSurfer SAMSEG when available
263+
264+
# LST-AI options
265+
export LSTAI_THRESHOLD=0.5 # lesion probability threshold (0-1; LST-AI default 0.5)
266+
export LSTAI_DEVICE="cpu" # "cpu" or a GPU id (e.g. "0")
267+
export LSTAI_DOCKER_IMAGE="jqmcginnis/lst-ai:latest" # used only if Docker back-end is selected
268+
269+
# SAMSEG options
270+
export SAMSEG_LESION_THRESHOLD=0.3 # lesion posterior threshold (run_samseg default 0.3)
271+
export SAMSEG_LESION_MASK_PATTERN="0 1" # one number per input (T1 FLAIR): 0=no constraint, 1=brighter-than-GM
272+
export SAMSEG_LESION_LABEL=99 # lesion label value in SAMSEG seg.mgz
273+
export SAMSEG_EXTRA_OPTS="--pallidum-separate" # extra run_samseg flags (recommended when FLAIR shows pallidum)
274+
247275
# Reference templates from FSL or other sources
248276
if [ -z "${FSLDIR:-}" ]; then
249277
log_formatted "WARNING" "FSLDIR not set. Template references may fail."

0 commit comments

Comments
 (0)