Population-template construction

What this step does

Bring multiple specimens into a common volumetric coordinate system. Segmentation-derived images initialize correspondence; aligned MRIs are averaged and iteratively refined into a population MRI template.

Specimen MRIs aligned to a population MRI template.

The volumetric branch of Figure 1a.

This is a separate research workflow under scripts/intensity_template, not an additional purple-mri run stage. It requires Bash, Greedy, greedy_template_average, Convert3D, jq and Python 3. Keep greedy_build_template.sh and pybatch.sh together.

Prepare inputs and manifests

Select specimens after checking image quality, coverage and tissue integrity. Each MRI and its segmentation must share physical coordinates. Use consistent anatomical orientation. When pooling hemispheres, apply and record an explicit reflection/correspondence transform where needed; changing an orientation label alone does not reflect anatomy.

The public example uses smoothed binary foreground from the reconstruction map:

c3d case001_surface_labels.nii.gz \
  -thresh 1 inf 1 0 -smooth-fast 0.4mm \
  -o case001_template_input.nii.gz

Create manifest_segm.csv without a header:

case001,/absolute/template_inputs/case001_template_input.nii.gz
case002,/absolute/template_inputs/case002_template_input.nii.gz

Use unique case IDs and absolute paths without spaces or commas for the shell driver. Configurations with masks enabled require a third mask-path column; the supplied examples disable masks. Keep study-specific tissue representations and parameters when reproducing an existing template.

Stage 1: segmentation initialization

From the repository root, print and review the schedule first:

DRIVER=scripts/intensity_template/greedy_build_template.sh
bash "$DRIVER" -p scripts/intensity_template/params_ssd.json \
  -i manifest_segm.csv -T case001 \
  -o /absolute/results/new_template_segm -S

Remove -S to execute. -T selects a manifest subject; -t instead selects an existing reference image. The SSD example has six outer iterations, numbered 0 to 5. Rigid and affine stages run at iterations 0 to 2; deformable registration and averaging run at iterations 1 to 5. Linear optimization uses 100x100x40x0; deformable optimization uses 200x100x50x10 with smoothing 1.2mm 0.1mm. The final example image is greedy_template_iter_05_image.nii.gz.

Stage 2: MRI initialization and refinement

Create a second headerless manifest, manifest_mri.csv, with the same case IDs and the corresponding native MRI paths. The initialization helper reslices those MRIs with the completed segmentation-stage warp and affine transform, averages the images and writes a manifest for the MRI stage:

python scripts/intensity_template/initialize_mri.py \
  --manifest manifest_mri.csv \
  --segmentation-dir /absolute/results/new_template_segm \
  --reference /absolute/results/new_template_segm/greedy_template_iter_05_image.nii.gz \
  --output /absolute/results/new_mri_initialization

bash "$DRIVER" -p scripts/intensity_template/params_ncc.json \
  -i /absolute/results/new_mri_initialization/manifest_mri_warped.csv \
  -t /absolute/results/new_mri_initialization/mri_initial_template.nii.gz \
  -o /absolute/results/new_template_mri

The helper requires a new output directory and the supplied segmentation schedule, whose final linear transform is the affine matrix. Its averaging options, -U 1 -N 0 .98 0 1, normalize MRI intensities for template building. The older warp_and_mri_init_template.sh remains a dataset-specific blueprint; the explicit helper avoids its hard-coded paths and iteration reference.

MRI refinement uses NCC with radius 2x2x2, ten outer iterations, linear schedule 100x100x40x0 and deformable schedule 200x100x50x10. In the supplied JSON, affine runs at iterations 0 to 1, deformation at 0 to 9, averaging at 1 to 9, and rigid registration at iteration 9. Negative endpoints count from the end: [-1,-1] selects the last iteration, rather than disabling a stage. The final example image is greedy_template_iter_09_image.nii.gz.

Map native measurements into the final template

MRI-stage transforms act on images already initialized in segmentation-template space. Preserve both stages when resampling a native measurement:

greedy -d 3 -rf final_mri_template.nii.gz -ri LINEAR \
  -rm native_thickness.nii.gz thickness_in_template.nii.gz \
  -r stage2_warp.nii.gz stage2_linear.mat \
     stage1_warp.nii.gz stage1_affine.mat

These are placeholder filenames for the actual per-case transforms. stage2_linear.mat means the transform used by the final reslice command: for the supplied MRI schedule, the last rigid update is newer than the earlier affine matrix. Read the log rather than assuming the affine file is final. Include any preceding orientation/reflection transform in the correct chain.

Use continuous interpolation for thickness and discrete label interpolation for anatomy. Keep thickness in millimeters; do not apply MRI intensity normalization to thickness. A saved forward warp does not establish a validated inverse; generate and check an inverse chain separately if needed.

Quality control and analysis

Review iteration templates and specimen overlays, especially cortical alignment, sampling margins and deformation plausibility. Keep manifests, reference grids, parameters and complete transform chains. Define the analysis mask, smoothing, covariates and multiple-comparison procedure before fitting voxel-based models. See Groupwise anatomical analysis for the distinction between voxel-based thickness analysis and deformation-based morphometry.

Source: template driver and MRI initialization helper. The driver derives from Paul Yushkevich’s Greedy template scripts.