-
Notifications
You must be signed in to change notification settings - Fork 0
Module 7 CAT12 VBM
What is a VBM analysis?
Voxel-based morphometry (VBM) allows you to assess group level behavioral relationships or group difference in gray matter structure (white matter can be done as well but typically isn't). It is based on estimations of brain matter density. Density is a proportion (think of it like the volume of a structure divided by head size).
As a side note: There’s some debate whether or not VBM measures volume or density. What it does depends on the tool and how the data are processed. Some processing of data for a VBM does what is called a modulation, which effectively transforms the density value into a volume (in effect, removes the adjustment for head size [this isn’t what’s going on but is close enough for our purposes]). However, there’s not clear consensus if the value is a volume or a density so I usually default to calling what you are comparing density, just to be safe.
In practice we are measuring gray matter volume differences or correlations with a VBM analysis; however, because there are additional factors to consider (e.g., whether or not to also include head size as a covariate: https://link.springer.com/article/10.1007/s11682-016-9656-9), I’ll use density and volume interchangeably when talking about an VBM analysis and usually default to density.
Watch this video comparing FreeSurfer with VBM: https://www.youtube.com/watch?v=TT8FJUq-QKo
If you’re interested in learning more about VBM, this is an important paper to read: https://www.fil.ion.ucl.ac.uk/spm/doc/papers/am_vbmreview.pdf
“VBM can be thought of as comparing the relative concentration of gray or white matter structures in the spatially normalized images (i.e. the proportion of gray or white matter to all tissue types within a region). There are cases, however, when the objective of the study is to identify regional differences in the volume of a particular tissue (gray or white matter), which requires the information about absolute volumes to be preserved. Here a further processing step, which is usually referred to as “modulation”, can be incorporated to compensate for the effect of spatial normalisation…. In short, the multiplication of the spatially normalised gray matter (or other tissue class) by its relative volume before and after warping has critical implications for the interpretation of what VBM is actually testing for. Without this adjustment, VBM can be thought of as comparing the relative concentration of gray or white matter structures in the spatially normalized images. With the adjustment, VBM can be thought of as comparing the absolute volume of gray or white matter structures. The two approaches are known as “non-modulated” and “modulated” VBM, respectively.”
So what this means is just think of this as a volume and don’t worry about the density aspect.
Note that this will require about 4-8 hours of processing (you don't have to do much during some of that time), but factor that into your schedule for working on this. Once the preprocessing (like what we did in Module 4) is done, the rest is relatively quick to do.
Once data are set up, running a VBM analysis is straightforward. The most challenging parts are quality assessment and setting up the GLM (General Linear Model). You do not need to worry about quality assessment for the class assignment. T1-weighted images are provided.
For the VBM analysis, organization of files depends on what type of analysis you are doing. If you are running a between-group analysis, the convention is to group or name all the "control" MRIs so they group together and all the "patient" MRIs so they group together. For example, prepend con_ for control and pat_ for patient. In CAT12 it's easiest to have all group MRI in one directory and another group in another directory. For the homework, this has already been done for you.
Data are stored in a directory called vbm, which is in /blue/psy4930/share/data/Module7
Copy that to your directory using the Terminal (or can use the file system in the browser in ood.ufl.edu):
cp -fr /blue/psy4930/share/data/Module7/vbm /blue/psy4930/share/students/{gatorlink}/
Use a Matlab session for this (I've had good experiences with Matlab R2024b but you can try a different version; I had some problems with 2025b). Request 8 cores, about 32 GB of RAM, and to be safe, request at least 24 hours. You will need to use psy4930-b under QoS (refer to the video) and make sure Cluster partition has "default" selected.
My tutorial is mostly based on one created by Dr. Jahn. You can refer to these. We are using different data but his guide is a great resource.
Step 1: https://andysbrainbook.readthedocs.io/en/latest/CAT12/CAT12_03_Preprocessing.html
Step 2: https://andysbrainbook.readthedocs.io/en/latest/CAT12/CAT12_04_Analysis.html
Here is the walk-through video: https://youtu.be/02gFRDUjlhY
Again, the preprocessing can take 6+ hours, so plan accordingly.
Note: Sometimes not all the brains complete preprocessing. The Matlab window should tell you how many completed. Another way to check is to run a command like this from your vbm directory:
for d in {Con,Sz}/sub-*/; do sub=$(basename "$d"); [ ! -f "${d}anat/catreport_${sub}_T1w.pdf" ] && echo "Missing: $d"; done
That will tell you which brains need to be re-processed. Select any that failed and process them before moving to the VBM analysis.
If you follow along with the video, you should have everything you need to submit the homework (a screenshot of results).
Below is a guide based on the video walk-through. Please refer to the guide by Dr. Jahn if anything is unclear.
https://andysbrainbook.readthedocs.io/en/latest/CAT12/CAT12_03_Preprocessing.html
https://andysbrainbook.readthedocs.io/en/latest/CAT12/CAT12_04_Analysis.html
This tutorial explains how to run a voxel-based morphometry (VBM) analysis on structural MRI data using CAT12, SPM12, and MATLAB.
Voxel-based morphometry (VBM) is a method for testing whether local gray matter volume or concentration differs across the brain. In a typical study, you start with T1-weighted structural MRI scans, preprocess them, and then test for voxelwise differences between groups.
In the example shown in the video, the goal is to compare two groups:
- controls
- people with schizophrenia
The same general workflow also applies to many other two-group studies.
You will complete the analysis in this order:
- Copy the VBM data into your own writable directory.
- Launch MATLAB on HiPerGator.
- Add SPM12 to the MATLAB path.
- Open CAT12 through SPM.
- Run segmentation/preprocessing on all structural scans.
- Confirm which subjects finished successfully.
- Reprocess any subjects that failed.
- Smooth the gray matter images.
- Extract total intracranial volume (TIV).
- Set up the second-level statistical model.
- Add model estimation and contrasts to the batch.
- Run the batch.
- Review the results carefully.
You should already have:
- access to HiPerGator
- access to MATLAB through an interactive session
- access to an SPM12 installation that includes CAT12
- a folder containing structural MRI files in
.niior.nii.gzformat - two subject groups organized into separate folders
This tutorial assumes your data are already arranged in two folders, one per group, and that each subject has a structural scan inside that folder structure.
Do not work directly in a shared class or lab directory. Copy the full VBM folder into a location that you own and can write to.
You can copy the folder with either the file browser or the terminal.
- Go to the shared data location.
- Find the VBM folder or
Module7folder. - Copy it.
- Navigate to your own working directory.
- Paste it there.
Your goal is to create your own full copy of the analysis folder, not to edit the shared original.
A recursive copy command was shown in the video. The exact paths will depend on your environment, but the general form is:
cp -fR /blue/psy4930/share/data/Module7 /blue/psy4930/$USER/Important points:
-
-Rmeans recursive, so the entire folder tree is copied. - the destination should be your folder
- check that the copy finished before moving on
After copying, confirm that the folder structure looks correct and that both group folders are present.
Launch MATLAB through an interactive session.
The video noted that MATLAB 2025b appeared unstable for this workflow, so use MATLAB 2024b unless you know a newer version works in your environment.
Suggested settings:
- MATLAB version: 2024b
- cores: 8
- memory: 32 GB RAM
- time: 24 hours
- account: psy4930
- QoS: psy4930-b
Preprocessing often takes several hours. A full run may take 6 hours or more, depending on the data and system load.
Once MATLAB opens, make sure SPM12 is on the MATLAB path.
In the MATLAB command window, type:
spmIf SPM opens without an error, the path is working. Continue with Step 4.
If spm does not open, add it to the path as described below.
- In MATLAB, open Set Path.
- Add the folder containing SPM12.
- Save the path.
Example SPM12 location:
/blue/psy4930/share/data/neurotools/spm12
A common problem is that MATLAB cannot save changes to the default path because the installation directory is protected.
If that happens:
- choose to save the path somewhere else
- save it to a writable location
- use your home directory unless you have another personal directory you prefer
Do not save your path settings into a shared class or lab directory unless that directory belongs to you.
In the MATLAB command window, type:
spmIf SPM opens without an error, the path is working.
After SPM opens:
- click Toolbox
- choose CAT12
If CAT12 does not appear, one of two things is usually wrong:
- you added the wrong SPM12 folder
- that SPM installation does not include CAT12
Fix that before moving on.
This is the main preprocessing step for the VBM analysis. Make sure you are in your directory within the MATLAB main window. For example, if your data are in /blue/psy4930/share/students/$USER/Module7/vbm, you should have that path in the MATLAB navigation bar near the top of the MATLAB window (not in SPM or CAT12). This will reduce the potential for permissions errors.
In CAT12:
- click Segment
- choose Volumes
- navigate to your copied VBM folder, not the shared original
- go to the top-level folder that contains both groups
- use a file filter such as
nii.* - use recursive selection so CAT12 searches through subfolders
In the example dataset, CAT12 should find 40 files total:
- 20 controls
- 20 individuals with schizophrenia
The control scans appear first because the folders are arranged so the control group comes first alphabetically. Keeping that order consistent is helpful later when you define the group model.
If CAT12 does not find the expected number of files, stop and fix the problem before continuing. Usually this means one of the following:
- some files did not copy
- you selected the wrong folder
- the file filter is wrong
- recursive selection was not used
After all expected files are selected:
- click Done
- confirm the file list looks correct
- click Run
CAT12 will then process each subject.
CAT12 preprocessing takes time. Do not assume it is finished just because MATLAB is still open.
Watch the MATLAB command window and CAT12 job windows. You should see subjects being processed one by one. CAT12 also generates logs that can help you identify failures.
A practical approach is to come back later and check the MATLAB session directly rather than expecting an email notification.
This is one of the most important parts of the workflow.
In the video example, only 27 of 40 subjects finished on the first attempt. The remaining 13 were incomplete or unknown. That means those subjects were not ready for group-level analysis.
For a completed subject, the subject's anat folder should usually contain:
- Four directories (label, MRI, report, surf)
- a CAT report PDF in the report directory
A completed subject typically has a file like this:
anat/report/catreport_sub-XXXX_T1w.pdf
If the CAT report is present, preprocessing likely completed successfully.
A failed subject may have:
- only a few files in the
anatfolder - no CAT report
Do not move on to group-level statistics until you know exactly which subjects finished and which did not.
If all subjects completed successfully, skip this step.
If some subjects failed, identify the incomplete cases and rerun only those subjects.
You can do this in either of two ways:
- inspect subject folders one by one for missing CAT reports
- use a terminal command to list incomplete cases automatically
From your VBM directory, a command like this can help:
for d in */sub-*/anat/report/; do
if [ -z "$(find "$d" -name "catreport_sub-*_T1w.pdf")" ]; then
echo "Missing report in: $d"
fi
doneThis command assumes:
- your group folders are named
ConandSz - subject folders are named like
sub-001
If your folder names differ, update the command accordingly.
To rerun failed cases:
- go back to CAT12 > Segment > Volumes
- select only the failed subject scans
- run segmentation again
Repeat until all intended subjects finish successfully.
After preprocessing is complete, the next step is to smooth the gray matter images.
Smoothing averages signal across neighboring voxels. In practice, this helps reduce noise and makes the data more appropriate for voxelwise statistical testing. This is conceptually similar to smoothing in functional MRI analyses.
For this tutorial, we are working with volumetric data, so we will use a smoothing kernel that is also common in fMRI workflows.
Check the video and here if you have any questions about the smoothing process.
In the SPM12 GUI:
- click Smooth
- double-click Images to smooth
- navigate to your
CAT12_Tutorialdirectory - enter
mwp1in the Filter field - click Rec to recursively find the files
- once the images are loaded, click Done
- keep the default smoothing kernel at
[8 8 8] - click the green Go button to run the job
The CAT12 manual recommends a smoothing kernel in the range of 6–8 mm. For this tutorial, keep the default value of [8 8 8].
This step should finish quickly. After it is done, check the output by loading all of the smoothed images with Check Reg.
The images should look visibly more blurred than the unsmoothed versions. That blurring is expected and confirms that the smoothing step was applied successfully.
Once preprocessing is complete, extract total intracranial volume (TIV).
People differ in overall head and brain size. Even after spatial normalization, those differences can still influence the VBM results. Including TIV as a covariate helps account for those global size differences.
From the CAT12 window:
- choose the option to get total intracranial volume
- point CAT12 to the processed subject output files
- save the extracted values
In the example dataset, CAT12 should find 40 text files containing intracranial volume information and then save a summary file such as:
TIV.txt
Open the TIV output file and confirm:
- there is one TIV value per successfully processed subject
- the number of rows matches the number of subjects you plan to analyze
- the order of TIV values matches the order of subjects in your second-level model
That last point is critical. A correct TIV file in the wrong subject order is still wrong.
After preprocessing, smoothing, and TIV extraction are complete, you are ready to build the group-level model.
You have two options for setting up a group-level analysis:
- click Basic Models in the CAT12 GUI
- click Specify 2nd-level in the SPM GUI
These are essentially doing the same thing. The main difference is that CAT12 Basic Models uses a factorial design by default. That design can be modified to do the same type of analysis as a two-sample t-test in SPM by specifying the appropriate factors and levels.
For this tutorial, use CAT12 > Basic Models.
Before opening the model, use the MATLAB terminal to navigate to your vbm directory, and then create a new folder for the second-level analysis:
mkdir 2ndLevelThis directory will store the design matrix and model outputs for the group analysis.
In the CAT12 GUI:
- click Basic Models
- double-click Directory
- select the new folder you just created:
2ndLevel
Under Factors:
- change the Name to
Group - set the number of Levels to
2
This creates a two-group design.
Under Cells:
- click New: Cell
- for the first cell, click Levels and enter
1 - double-click Scans
- navigate to the
Condirectory - in the Filter field, type
smwp1 - click Rec
- click Done
Then repeat the same process for the second group:
- click New: Cell
- set Levels to
2 - double-click Scans
- navigate to the
Szdirectory - in the Filter field, type
smwp1 - click Rec
- click Done
This assigns the smoothed gray matter maps for the Con group to level 1 and the Sz group to level 2.
In the Covariates field:
- select New: Covariate
- double-click Name and enter
TIV - double-click Vector
- copy and paste the values from the
TIV.txtfile you generated earlier
Leave the remaining covariate defaults unchanged.
When you use CAT12 Basic Models, CAT12 automatically includes another module called Check design orthogonality and homogeneity.
This step loads the design file you just created and checks for problems such as high correlations between covariates and other regressors in the model. Leave the defaults unchanged for this tutorial.
To save time and make the workflow more efficient, add the estimation step to the same batch instead of running it separately afterward.
In the Batch Editor menu, click:
SPM -> Stats -> Model Estimation
This adds a Model Estimation module to the batch.
Then:
- click the new Model Estimation module
- highlight the Select SPM.mat field
- click Dependency in the lower-right corner of the Batch Editor
- select the
SPM.matdependency from the Factorial design specification module
This tells SPM to estimate the model that you just specified in the previous step.
After adding the model estimation step, add the contrast manager so the design, estimation, and contrasts can all be run in one batch.
In the Batch Editor menu, click:
SPM -> Stats -> Contrast Manager
This adds a Contrast Manager module to the batch.
Then:
- click the Contrast Manager module
- highlight the Select SPM.mat field
- click Dependency
- select the
SPM.matfile from the Model Estimation step
This links the contrast manager to the model that was just estimated.
Click on Contrast Sessions and create two new T-contrasts.
Because the Con group was entered first and the Sz group was entered second, the first contrast weight corresponds to Con and the second corresponds to Sz.
For the first T-contrast:
-
Name:
Con-Sz -
Weights:
1 -1
This tests for regions in which the Con group shows greater gray matter values than the Sz group.
For the second T-contrast:
-
Name:
Sz-Con -
Weights:
-1 1
This tests for regions in which the Sz group shows greater gray matter values than the Con group.
Once everything is connected:
- review the batch carefully
- confirm that the correct scans are in each group
- confirm that the TIV values are in the correct subject order
- click the green Go button
SPM/CAT12 will then:
- specify the factorial design
- check design orthogonality and homogeneity
- estimate the model
- generate the contrasts
After the batch finishes, you can move on to reviewing the statistical results.
Once the model is estimated and contrasts are run, review the statistical maps and tables carefully.
- the design matrix looks reasonable
- the subject count matches the subjects you intended to analyze
- covariates were entered correctly
- the contrast direction matches your coding
- significant clusters are anatomically plausible
A significant cluster is only meaningful if the preprocessing and model setup were correct. Subject-order mistakes, missing subjects, or mismatched TIV values can invalidate the analysis.
Use this checklist before trusting your results.
- I copied the VBM folder into my own directory.
- I am not working in the shared directory.
- My two groups are in separate folders.
- MATLAB launched successfully.
- SPM12 opens when I type
spm. - CAT12 appears in the SPM toolbox menu.
- I selected the correct
.niior.nii.gzfiles recursively. - The total number of selected files matches what I expected.
- CAT12 finished processing all intended subjects.
- Each completed subject has a CAT report.
- Any failed subjects were identified.
- Failed subjects were rerun until complete.
- I extracted TIV values.
- TIV order matches subject order.
- My second-level factor has two levels.
- I assigned the correct group scans to each cell.
- My contrasts match my group coding.
Cause: SPM12 is not on the MATLAB path.
Fix: Add the correct SPM12 folder using Set Path and save the path to a writable location such as your home directory.
Cause: The wrong SPM folder was added, or CAT12 is not included in that installation.
Fix: Recheck the SPM12 location and make sure CAT12 is present.
Cause: Wrong folder, wrong file filter, incomplete copy, or recursive selection was not used.
Fix: Go back to your copied VBM folder, use the correct filter, enable recursive selection, and confirm all files copied correctly.
Cause: CAT12 preprocessing failed for those cases.
Fix: Look for missing CAT reports, identify the failed subjects, and rerun segmentation on just those subjects.
Cause: You are trying to write to a protected location.
Fix: Save the path to your home directory or another writable location.
Cause: There might be a compatibility problem with that version, as mentioned in the video.
Fix: Use MATLAB 2024b unless you know a newer version works in your setup.
A VBM analysis with CAT12 has two major stages.
First, you preprocess each subject's structural scan with CAT12. This produces a file with only gray matter of the brain that has been lined up with a reference brain. Before doing any statistics, you must confirm that every intended subject actually finished and rerun any failures.
Second, you build a statistical model using the processed scans, assign scans to groups, and include covariates such as TIV. If your subject order and covariate order are correct, you can then test for group differences across the brain.
The most common beginner mistakes in this workflow are usually organizational, not technical.
They include:
- working in the wrong directory
- selecting the wrong files
- missing failed preprocessing cases
- mismatching subject order between scans and covariates
- forgetting which group was coded first
If you stay organized and verify each step before moving on, you avoid most of the serious problems.
For this assignment, please upload a screenshot of the Matlab session showing some results.