WHIM Practical

In this practical, you will discover how to use whim to run fixel-based analysis, including creating a fixel template, extracting fibre-specific information from diffusion MRI, and running group-level comparisons.

A fixel represents an individual fibre population within a voxel, allowing for the resolution of crossing fibres. Fixel-based analysis (FBA) models these fibre populations separately to extract fibre-specific metrics, enabling more precise and anatomically informed comparisons across subjects.

WHIM constructs a fixel template using a discrete fibre orientation distribution model that explicitly defines fixels. This template serves as a prior for estimating subject-level fibre orientations and extracting fixel-specific metrics such as signal fractions or diffusivities. Because fixels are consistently defined across subjects, WHIM enables robust statistical comparisons of microstructural properties related to ageing, disease, or other group-level factors in diffusion MRI.


Requirements for Running WHIM

To run whim for a study, you will need the following:

Contents:

View the Fixel Template in FSLeyes
Inspect the pre-generated fixel template visually.
Extract Fixel-Specific Metrics Using a Fixel Template
Extract fibre-specific features such as signal fractions and diffusivities from diffusion MRI data using a fixel template.
Run Statistical Analysis on Fixel-Specific Data
Perform group-level statistical comparisons to identify significant microstructural differences using fixel-specific metrics.
Create a Fixel Template
Generate a population-based fixel template by spatially aligning fibre orientation distributions across subjects.



View the Fixel Template in FSLeyes

The fixel template is a probabilistic representation of white matter fibre architecture across subjects in a common space. For each voxel, it defines the number of fixels (distinct fibre populations), their average orientations (dyads), and the variance of these orientations across subjects. This structure ensures fibre-specific consistency and comparability across individuals.

The fixel template is stored in the template directory, which contains the following files:

To visualise the fixel template, use the following fsleyes command:

fsleyes "$FSLDIR/data/omm/Oxford-MM-1/OMM-1_T1_brain.nii.gz" \
  "template/f_1_mean.nii.gz" --disabled \
  "template/dyads_1_mean.nii.gz" --overlayType linevector --lineWidth 2 \
    --clipImage template/f_1_mean.nii.gz --clippingRange 0.001 1 \
  "template/f_2_mean.nii.gz" --disabled \
  "template/dyads_2_mean.nii.gz" --overlayType linevector --lineWidth 2 \
    --clipImage template/f_2_mean.nii.gz --clippingRange 0.001 1 \
  "template/f_3_mean.nii.gz" --disabled \
  "template/dyads_3_mean.nii.gz" --overlayType linevector --lineWidth 2 \
    --clipImage template/f_3_mean.nii.gz --clippingRange 0.001 1

This command renders fibre orientation lines (dyads) in each voxel, thresholded by their corresponding signal fractions (f_i_mean). Use axial, sagittal, and coronal views to explore major fibre crossings across the brain.

In which region(s) of the brain do you observe more than one fibre orientation per voxel?

💡 Hint: Look around the centrum semiovale or near where the corpus callosum intersects with the corticospinal tracts. These areas often exhibit clear fibre crossings.


Extract Fixel-Specific Metrics Using a Fixel Template

digraph FixelExtraction { rankdir=TB; node [shape=box style=filled fillcolor="#f9f9f9" color="#cccccc" fontname="Helvetica"]; subgraph cluster_subject { label = "Subject-Specific Inputs"; style = "dashed"; color = "#e6f7cd"; S1 [label="dMRI data"]; S2 [label="xfm (diff2std)"]; } subgraph cluster_template { label = "Fixel Template"; style = "dashed"; color = "#d0e4f7"; T1 [label="Fibre orientation priors"]; T2 [label="Brain mask\n(template space)"]; } S3 [label="Biophysical model\n(e.g. bas_dperp)"]; P1 [label="Fit FIXEL template to the subject dMRI data \n(whim metrics)"]; O1 [label="Fixel-specific parameter estimates"]; T1 -> P1; T2 -> P1; S1 -> P1; S2 -> P1; S3 -> P1; P1 -> O1; }

Once a fixel template is created (or an existing one is used), the next step involves extracting fibre-specific microstructural features for each subject. These features are aligned to the fixel template, ensuring spatial and structural consistency across subjects for meaningful comparisons.

WHIM performs this extraction using the whim metrics command. It fits a biophysical model to the subject's diffusion MRI data, using the fixel template to provide prior information about fibre orientations.

Tip: Looping over multiple subjects

You can automate metric extraction across all subjects using a Bash for loop. For example, if your subject folders are named ./data/001, ./data/002, etc., you can run:

for subj in ./data/*; do
 id=$(basename "$subj")
 whim metrics --template ./template \
 --data $subj/diffusion/data.nii.gz \
 --bvals $subj/diffusion/bvals \
 --bvecs $subj/diffusion/bvecs \
 --xfm $subj/xfms/mmorf_diff2OMM.nii.gz \
 --mask slice_mask_2mm.nii.gz \
 --output fixels/$id
done
Why does WHIM use a template to guide feature extraction rather than fitting orientations independently for each subject?

To extract fixel-specific metrics for a single subject, run:

whim metrics --template ./template \
             --data ./data/001/diffusion/data.nii.gz \
             --bvals ./data/001/diffusion/bvals \
             --bvecs ./data/001/diffusion/bvecs \
             --xfm ./data/001/xfms/mmorf_diff2OMM.nii.gz \
             --mask slice_mask_2mm.nii.gz \
             --output fixels/001

Arguments:

This command produces a set of parameter maps (e.g. f_1_std.nii.gz, d_perp_1_std.nii.gz) in template space, each corresponding to a specific fixel.

The whim metrics command produces a set of fixel-wise parameter maps that characterise the white matter microstructure in each subject. The most important outputs include

You can visualise the output of whim metrics for a single subject using FSLeyes. The following command overlays the estimated fibre orientations (dyads_i_std.nii.gz) as line vectors, modulated by their corresponding signal fractions (f_i_std.nii.gz):


fsleyes ./fixels/001/f_1_std.nii.gz --disabled \
./fixels/001/dyads_1_std.nii.gz --overlayType linevector \
--modulateImage ./fixels/001/f_1_std.nii.gz --lineWidth 2.0 \
--modulateRange 0.0 0.3 --modulateMode alpha \
./fixels/001/f_2_std.nii.gz --disabled \
./fixels/001/dyads_2_std.nii.gz --overlayType linevector \
--modulateImage ./fixels/001/f_2_std.nii.gz --lineWidth 2.0 \
--modulateRange 0.0 0.3 --modulateMode alpha \
./fixels/001/f_3_std.nii.gz --disabled \
$subj/dyads_3_std.nii.gz --overlayType linevector \
--modulateImage ./fixels/001/f_3_std.nii.gz --lineWidth 2.0 \
--modulateRange 0.0 0.3 --modulateMode alpha

This display allows you to examine the spatial distribution of fibre orientations and their relative strengths within each voxel. The line opacity is modulated by the signal fraction, so stronger fixels appear more prominently. This helps you inspect fibre crossings and confirm that the fixel estimates align well with white matter structures.

Try visualising the perpendicular diffusivity (d_per_i_std.nii.gz) maps for each fibre using FSLeyes. How do these values differ across the brain?

Bonus: Can you repeat the visualisation using the *_native.nii.gz outputs to see the results in the subject's native space? What changes do you notice?

WHIM uses the fixel template to constrain and stabilise model fitting. Unlike BEDPOSTX that estimate orientations independently per subject, WHIM's template-driven approach ensures consistent fixel labelling (yet across subject variability in orientation) across subjects - enabling valid group-level comparisons.



Run Group-Level Statistical Analysis

digraph FixelGLM { rankdir=TB; node [shape=box style=filled fillcolor="#f9f9f9" color="#cccccc" fontname="Helvetica"]; I1 [label="Fixel-specific parameters\n(from all subjects)"]; I2 [label="Brain mask\n(in template space)"]; I3 [label="Design matrix (EVs)"]; I4 [label="Contrasts"]; I5 [label="Subject list"]; P1 [label="Run statistical analysis\n(whim glm)"]; O1 [label="Group-level fixel statistics"]; I1 -> P1; I2 -> P1; I3 -> P1; I4 -> P1; I5 -> P1; P1 -> O1; }

Once fixel-specific metrics have been extracted for all subjects, you can perform group-level statistical analysis using the whim glm command. This step tests for differences in fixel metrics (e.g., signal fractions, diffusivities) between groups, using the General Linear Model (GLM) framework.

WHIM's GLM implementation aligns closely with FSL-style design, where you provide a matrix of explanatory variables (EVs), a set of contrast vectors, and a mask defining where to analyse.

To run a GLM on the fixel features of all subjects, use:

whim glm --subjectdirs fixels/001 fixels/002 fixels/003 fixels/004 fixels/005 fixels/006 \
         --des design.mat \
         --con design.con \
         --mask slice_mask_2mm.nii.gz \  
         --output stats

Arguments:

WHIM will perform the GLM fit for each fixel metric separately and generate output files including:

You can visualise group differences using FSLeyes. For example, to view z-scores for the first contrast:

To visualise the results of the group-level GLM on fixel metrics, you can overlay each dyad orientation and colour it by the corresponding z-score using FSLeyes. The following shell loop iterates over each fibre (1 to 3), adds the dyad vectors, and colours them using the render3 colormap based on the statistical z-scores. It also clips the display using the signal fraction to only show meaningful fixels:

  stats=./stats
  template=./template
  struct="$FSLDIR/data/omm/Oxford-MM-1/OMM-1_T1_brain.nii.gz" \
  args="$struct"
  for nf in 1 2 3; do
      args="$args \
      $stats/f_${nf}_zscore.nii.gz --disabled \
      $template/f_${nf}_mean.nii.gz --disabled \
      $template/dyads_${nf}_mean.nii.gz --overlayType linevector \
      --cmap render3 --colourImage $stats/f_${nf}_zscore.nii.gz \
      --clipImage $template/f_${nf}_mean.nii.gz --lineWidth 2.0 \
      --colourRange -100.0 100.0 --clippingRange 0.001 1"
  done
  
  eval "fsleyes ${args}"

This will open FSLeyes with all visible fixels coloured according to their GLM z-scores, while suppressing low-signal regions to enhance visual clarity.

The GLM can test for a wide range of effects, such as group differences, correlations with age, or interactions. For details on constructing design.con and design.mat, refer to FSL's GLM documentation. In this case the desing.mat contains three columns, the bias term, dummie variable to indicate sex (1 and -1), and age of the subjects. The contrast indicates to test for sex and keep age as a covariate.
What information is contained in f_1_zscore.nii.gz and how does it relate to your study hypothesis?



Create a Fixel Template (Optional)

digraph TemplateCreation { rankdir=TB; node [shape=box style=filled fillcolor="#f9f9f9" color="#cccccc" fontname="Helvetica"]; subgraph cluster_common { label = "Common Inputs"; style = "dashed"; color = "#cde7f7"; C1 [label="bvals"]; C2 [label="bvecs"]; C3 [label="brain mask"]; } subgraph cluster_subject { label = "Subject-Specific Inputs"; style = "dashed"; color = "#e6f7cd"; S1 [label="dMRI data"]; S2 [label="xfm (diff2std)"]; } F1 [label="whim subject"]; P1 [label="Subject fibre orientation estimates"]; G1 [label="whim group"]; G2 [label="Group-level fibre orientation estimates\n(means and variances)"]; T1 [label="whim select\n(model selection across fibre counts)"]; T2 [label="Fixel template"]; C1 -> F1; C2 -> F1; C3 -> F1; S1 -> F1; S2 -> F1; F1 -> P1; P1 -> G1; G1 -> G2; G2 -> F1 [label="repeat until convergence", style=dashed]; G2 -> T1 [label="repeat for 1, 2, 3 fibres"]; T1 -> T2; }

The first step in fixel-based analysis is to build a fixel template. This template defines the number of fixels in each voxel, the average fibre orientations, and the variance of those orientations across subjects.

WHIM uses a hierarchical modelling framework to estimate fibre-specific microstructural properties. To simplify template construction, WHIM provides the whim EM command, which internally alternates between fitting individual subjects (whim subject) and updating the group-level priors (whim group) over several EM iterations.

For efficient data handling and parallel processing, WHIM leverages fsl-pipe and file-tree. Instead of specifying individual file paths, you provide a single file-tree text file that describes where to find the necessary inputs (e.g. dMRI data, bvecs, bvals, transforms) for each subject. fsl-pipe uses this structure to automatically generate and manage the required tasks, either submitting them to a compute cluster or running them locally in the correct order.

This process must be repeated for models with 1, 2, and 3 fibres per voxel. WHIM then applies voxel-wise model selection - typically using the BIC criterion - to determine the optimal number of fibres per voxel.

Note on Registration:
The transformation to standard space (--xfm) can technically be derived from any modality, but we strongly advise using multimodal registration that includes diffusion data. T1-weighted images offer poor contrast in white matter, which can lead to misalignment of fibre structures if used alone. For optimal fixel correspondence across subjects, we recommend using a multimodal tool such as MMORF and registering to a multimodal template like the Oxford Multi-Modal Template (OMM-1) rather than the traditional MNI template.

To run the full EM fitting for a single fibre model, use:

whim EM --file-tree ../data/data.tree --mask slice_mask_2mm.nii.gz --nf 1 --iters 3 --output ./pes

Arguments:

About input.tree

The input.tree file defines the layout of your dataset using file-tree syntax. It tells WHIM and fsl-pipe where to find required input files for each subject, enabling automated and scalable processing.

In your setup, the data directory looks like this:

  data
    {subject}
      diffusion
        bvals (bvals)
        bvecs (bvecs)
        data.nii.gz(data)
        nodif_brain_mask.nii.gz
      xfms
        T1.nii.gz
        dti2mni_transf.nii.gz (diff2std)
  

WHIM expects that the input.tree file maps each required file (e.g., data, bvals, bvecs, diff2std) using the corresponding template keys defined with those exact names. The actual folder structure can vary as long as the keys are correctly assigned.

After running this process separately for --nf 1, 2, and 3, we need to select the right number of fixels per voxel. This can be done by bayesian model selection. You can create the final fixel template using:

whim select --modeldirs ./pes/iteration_3/group/bas1 \ 
                        ./pes/iteration_3/group/bas2 \
                        ./pes/iteration_3/group/bas3 \
            --mask slice_mask_2mm.nii.gz \
            --output ./study_template/

This command selects the best-fitting model per voxel and generates a complete fixel template containing:

Compare this step with bedpostx. What aspects are shared, and what are fundamentally different?



The End.