DDSurfer reconstructs white and pial cortical surfaces from diffusion MRI.
Preprocessing, surface inference and optional postprocessing are provided in
one workflow, with model weights loaded automatically from weights/.
Diffusion MRI in. White and pial surfaces for both hemispheres out.
Publication
DDSurfer is published in Advanced Science:
Chengjin Li, Wei Zhang, Xi Zhu, Yuqian Chen, Nir A. Sochen, Jarrett Rushmore,
Carl-Fredrik Westin, Yogesh Rathi, Lauren J. O’Donnell, Ofer Pasternak, and
Fan Zhang. “DDSurfer: A Weakly-Supervised Dual-Stream Deep Learning Framework
for Cortical Surface Reconstruction From Diffusion MRI.”
Advanced Science 13(56), e76596 (2026).
If you use DDSurfer in academic research, please cite our paper.
Machine-readable citation information is available in CITATION.cff.
Citation (BibTeX)
@article{Li2026DDSurfer,
author = {Li, Chengjin and Zhang, Wei and Zhu, Xi and Chen, Yuqian and
Sochen, Nir A. and Rushmore, Jarrett and Westin, Carl-Fredrik and
Rathi, Yogesh and O'Donnell, Lauren J. and Pasternak, Ofer and
Zhang, Fan},
title = {DDSurfer: A Weakly-Supervised Dual-Stream Deep Learning Framework
for Cortical Surface Reconstruction From Diffusion MRI},
journal = {Advanced Science},
year = {2026},
volume = {13},
number = {56},
pages = {e76596},
doi = {10.1002/advs.76596},
url = {https://doi.org/10.1002/advs.76596}
}
Overview

DDSurfer at a glance. Weak supervision, white and pial surface reconstruction,
surface-based analysis and integration with 3D Slicer.
Installation
Recommended: For the easiest setup and interactive use, we recommend running
DDSurfer through the SlicerDSpace 3D Slicer extension — see the
SlicerDSpace Official Website
(GitHub).
For command-line use, clone the repository and enter the project directory:
git clone https://github.com/NeuroDMRI/DDSurfer.git
cd DDSurfer
The model weights are included in the repository. Set up the
Python environment and install the required
external applications before running the pipeline.
Run the commands below from the repository root.
Provide corrected 4D DWI, bval, bvec and a brain mask on the same native voxel
grid. No precomputed DTI or structural MRI is required. If a mask is unavailable,
enable optional brain masking; it is off by default.
inputs/<subID>/
dwi.nii.gz
dwi.bval
dwi.bvec
mask.nii.gz
Before running: motion, eddy-current and susceptibility correction, together
with the corresponding gradient updates, must already be done.
Run DDSurfer
Quick Start
From the repository root:
python3 run_ddsurfer_pipeline.py --subject <subID>
# Equivalent shell entry point:
bash run_ddsurfer_pipeline.sh --subject <subID>
For files stored elsewhere:
python3 run_ddsurfer_pipeline.py --subject <subID> \
--dwi ./data/dwi.nii.gz --bval ./data/dwi.bval \
--bvec ./data/dwi.bvec --mask ./data/mask.nii.gz
Workflow
DWI -> DTI features -> MNI inference -> native surfaces
Preprocessing runs automatically before surface prediction.
Default paths:
- Inputs:
inputs/<subID>/
- Outputs:
outputs/<subID>/
Common Options
| Option |
Usage |
--raw-input-root <path> |
Change the input directory. |
--output-root <path> |
Change the output directory. |
--device cuda:0 or --device cpu |
Select GPU or CPU inference. |
--precision fp32 |
Default on CPU and GPU; use the same precision across devices. |
--precision bf16 |
Optional mixed precision to reduce GPU memory use; requires BF16-capable CUDA hardware. |
--precision auto |
Follow the model manifest on CUDA (FP32 for the bundled models); FP32 on CPU. |
--cpu-threads 4 |
CPU thread budget for inference; default: 4. |
--max-gpu-gib 24 |
GPU allocation budget for inference in GiB; default: 24. |
--auto-mask |
Generate a missing brain mask with FreeSurfer SynthStrip; default: off. |
--preprocess-jobs 2 |
Run independent DTI stages concurrently; default: 1. |
--no-surface-refinement |
Disable default native-space surface refinement. |
--post-process |
Use source-built or installed FreeSurfer surface tools; default: off. |
--postprocess-backend |
Select auto (default), native or freesurfer. |
--keep-cache |
Retain intermediate files and detailed stage logs. |
--resume |
Reuse completed, checksum-verified results, even after cache cleanup. |
Before image processing starts, the pipeline checks inputs, model assets,
device/precision support and the required Slicer modules. FreeSurfer tools,
license and atlas files are checked only when postprocessing is requested;
automatic masking checks SynthStrip separately. A subject-wide lock prevents
two main-pipeline runs from writing or cleaning the same output directory.
The resource limits apply to inference, not registration or postprocessing.
CUDA inference requires a budget of at least 8 GiB, plus a 4-GiB free-memory
margin. Preflight cannot reserve the GPU against other processes.
CPU and GPU Precision
CPU and GPU inference use the same models and coordinate transforms, with
FP32 by default. Results should be close, but are not guaranteed to be bitwise
identical across devices.
To use FP32 on either device:
python3 run_ddsurfer_pipeline.py --subject <subID> --device cpu --precision fp32
python3 run_ddsurfer_pipeline.py --subject <subID> --device cuda:0 --precision fp32
If GPU memory is insufficient, explicitly select BF16 on supported hardware:
python3 run_ddsurfer_pipeline.py --subject <subID> --device cuda:0 --precision bf16
There is no automatic precision downgrade. BF16 reduces numerical precision and
can change surface coordinates; it is not merely a faster execution mode.
Compare devices using identical preprocessed inputs, weights and settings.
See PyTorch’s numerical accuracy guidance.
Cache and Reuse
DTI maps and surfaces are saved automatically. Intermediate cache is removed
after success; failed runs retain it for diagnosis. Source inputs are never
modified or removed.
To reuse final results without retaining the cache:
python3 run_ddsurfer_pipeline.py --subject <subID> --resume
Reuse requires a successful run record, matching inputs, weights, templates,
settings and implementation, and intact output checksums. Otherwise, the
pipeline attempts a normal run; existing cache/input safety checks still apply.
Older results without a reuse record are not skipped. Keep the original run
options when adding --resume; reuse does not recreate a deleted cache.
--skip-preprocessing instead uses an existing retained preprocessing cache.
It cannot be combined with --resume.
To verify the bundled weights:
(cd weights && sha256sum -c SHA256SUMS)
Optional Brain Masking
If no mask is available, add --auto-mask:
python3 run_ddsurfer_pipeline.py --subject <subID> --auto-mask
# Or supply the three diffusion files explicitly:
python3 run_ddsurfer_pipeline.py --subject <subID> --auto-mask \
--dwi ./data/dwi.nii.gz --bval ./data/dwi.bval --bvec ./data/dwi.bvec
- Default: off. Without this option, a mask is required.
- Method: FreeSurfer
mri_synthstrip on the mean b0 image (b <= 50).
- Setup: configure
FREESURFER_HOME, or pass --freesurfer-home <path>.
- Execution: CPU only;
--mask-threads 4 sets the thread budget.
- Output:
dti/<subID>-brainmask.nii.gz, retained after cache cleanup.
A supplied mask always takes priority. Automatic masking neither replaces it
nor enables surface postprocessing. Inspect the generated mask before using
the results in an analysis; it need not match a manually supplied mask.
See mask generation and validation.
Outputs
DTI maps, reconstructed surfaces and concise logs are retained for every run.
The FreeSurfer analysis directories are added only with --post-process:
outputs/<subID>/
dti/
<subID>-FA.nii.gz
<subID>-MD.nii.gz
<subID>-MinEigenvalue.nii.gz
<subID>-MidEigenvalue.nii.gz
<subID>-MaxEigenvalue.nii.gz
<subID>-Trace.nii.gz
<subID>-brainmask.nii.gz if generated with --auto-mask
ddsurfer/
lh.white.obj
lh.pial.obj
rh.white.obj
rh.pial.obj
surf/ optional postprocessing
lh.white, lh.pial, rh.white, rh.pial
lh.curv, lh.sulc, lh.thickness, lh.area
lh.inflated, lh.sphere, lh.sphere.reg
rh.* corresponding right-hemisphere results
label/ optional cortex labels and parcellations
lh.cortex.label, rh.cortex.label
lh.aparc.annot, rh.aparc.annot
lh.aparc.a2009s.annot, rh.aparc.a2009s.annot
stats/ optional regional surface statistics
lh.aparc.stats, rh.aparc.stats
lh.aparc.a2009s.stats, rh.aparc.a2009s.stats
fsaverage/ optional standard-surface overlays
lh.thickness.mgh, rh.thickness.mgh, ...
mri/ optional FreeSurfer reference volumes
brain.mgz, orig.mgz
logs/ run summary and execution logs
Atlas and hemisphere selections determine which postprocessing files appear.
See the postprocessing output guide for
file types and interpretation.
Optional Postprocessing
Plug-and-play surface analysis, disabled by default. Choose locally compiled
components or an existing FreeSurfer installation. No precompiled executable
package is shipped.
For the local-source route, prepare the build tools,
compile once, then run:
python -m postprocessing.core.build --jobs 4
export FS_LICENSE=/path/to/license.txt
python3 run_ddsurfer_pipeline.py --subject <subID> --post-process \
--postprocess-backend native
If FreeSurfer is already installed, use it directly instead:
python3 run_ddsurfer_pipeline.py --subject <subID> --post-process \
--postprocess-backend freesurfer --freesurfer-home /path/to/freesurfer
The default auto backend uses a configured FreeSurfer installation, otherwise
completed local components. Normal runs never download or compile source.
Local builds are being validated on Linux; macOS is unverified and native
Windows is unsupported. Both routes retain the original surface algorithms and
require a valid FreeSurfer license.
Postprocessing also accepts four native white/pial surfaces from other methods,
without DWI, DTI or structural MRI. Outputs include curvature, sulcal depth,
thickness, area, cortical parcellations, regional statistics and fsaverage overlays.
See the postprocessing guide for the
workflow, independent use and
optimizations.
Key Dependencies
| Component |
Purpose |
Requirement |
| Python 3.8+ |
Pipeline and utilities |
Required |
| PyTorch, torchvision |
Surface inference |
Required; CUDA optional |
| NumPy, SciPy, SimpleITK, nibabel, trimesh, pynrrd |
Image and surface processing |
Required |
| Slicer with SlicerDMRI |
Raw-DWI processing |
Set SLICER_PATH or put Slicer on PATH |
| Native surface tools |
Optional postprocessing |
Build locally or use an existing FreeSurfer installation; valid license required |
| C/C++ compiler, Git, CMake >=3.24,<4 |
Local-source setup only |
Not required when using an existing FreeSurfer installation |
| FreeSurfer SynthStrip |
Optional brain masking |
Separate setup; not included in the surface runtime |
Python Environment
Python dependencies for preprocessing, inference and postprocessing are defined
in requirements.txt at the repository root. The root
environment.yml creates a ddsurfer conda environment
and installs the same requirements. From the repository root:
conda env create -f environment.yml
conda activate ddsurfer
Alternatively, install into an existing compatible Python environment:
python -m pip install -r requirements.txt
Slicer/SlicerDMRI and optional SynthStrip must be configured separately; they are
not provided by these Python dependency files. Surface postprocessing uses
locally compiled components or a configured FreeSurfer installation.
The optional training helper utils/loss.py provides the original
single-directional Chamfer boundary loss. It requires a separately installed,
compatible PyTorch3D build;
the inference pipeline does not import it or require PyTorch3D.
Environment Check
Check your active environment before processing any subjects:
python tests/check_environment.py
This checks Python imports and package versions, plus the Slicer/SlicerDMRI CLI
files used by raw-DWI preprocessing. To check a CUDA GPU and optional FreeSurfer
components as well:
python tests/check_environment.py --device cuda:0 --post-process --auto-mask
- Add
--precision bf16 to check BF16 support on the selected GPU; FP32 is the default.
- Select the local-source or installed-FreeSurfer route with
--postprocess-backend; configure its license.
--auto-mask separately checks SynthStrip through FREESURFER_HOME or --freesurfer-home.
- Use
--skip-slicer only when you do not need to check raw-DWI preprocessing.
Missing components are reported with installation commands, download links or
configuration hints. No packages are downloaded or installed, and no data processing
or model inference runs. Missing local components are reported with the build
command; no compilation is triggered. Exit status is 0 when requested checks pass (warnings
may remain), and 1 when a required component fails. Native-library dependencies
are checked with ldd; processing commands, license validity and available
memory for a full inference run are not tested.
Slicer Extension
DDSurfer is available as a 3D Slicer extension in SlicerDSpace:
Official Website |
GitHub Repository.
Surface OBJ files declare SPACE=RAS in their header for automatic coordinate
selection in 3D Slicer. For older outputs without this declaration, select
RAS in the Add Data options when loading the surfaces.
License
DDSurfer is released under the MIT License. Third-party components
and external tools remain subject to their respective licenses. The reused
native source and atlas data retain the FreeSurfer license
and their third-party notices.
Support
For questions, bug reports or feature requests, please open a
GitHub issue.
Acknowledgments
This work is supported in part by the National Key R&D Program of China
(No. 2023YFE0118600) and the National Natural Science Foundation of China
(No. 62371107).
评论