Skip to content

Module 7 CAT12 VBM

Jared Tanner edited this page Apr 21, 2026 · 24 revisions

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

Tutorial: Running a VBM Analysis with CAT12, SPM12, and MATLAB

This tutorial explains how to run a voxel-based morphometry (VBM) analysis on structural MRI data using CAT12, SPM12, and MATLAB.

What VBM does

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.


Overview of the workflow

You will complete the analysis in this order:

  1. Copy the VBM data into your own writable directory.
  2. Launch MATLAB on HiPerGator.
  3. Add SPM12 to the MATLAB path.
  4. Open CAT12 through SPM.
  5. Run segmentation/preprocessing on all structural scans.
  6. Confirm which subjects finished successfully.
  7. Reprocess any subjects that failed.
  8. Smooth the gray matter images.
  9. Extract total intracranial volume (TIV).
  10. Set up the second-level statistical model.
  11. Add model estimation and contrasts to the batch.
  12. Run the batch.
  13. Review the results carefully.

Before you start

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 .nii or .nii.gz format
  • 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.


Step 1: Copy the data into your own directory

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.

Option A: Copy with the file browser

  1. Go to the shared data location.
  2. Find the VBM folder or Module7 folder.
  3. Copy it.
  4. Navigate to your own working directory.
  5. Paste it there.

Your goal is to create your own full copy of the analysis folder, not to edit the shared original.

Option B: Copy with the terminal

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:

  • -R means 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.


Step 2: Launch MATLAB on HiPerGator

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.


Step 3: Check if SPM12 is in the MATLAB path

Once MATLAB opens, make sure SPM12 is on the MATLAB path.

In the MATLAB command window, type:

spm

If 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.

What to do if spm is not on the path

  1. In MATLAB, open Set Path.
  2. Add the folder containing SPM12.
  3. Save the path.

Example SPM12 location:

/blue/psy4930/share/data/neurotools/spm12

Common issue: MATLAB cannot save the default path

A common problem is that MATLAB cannot save changes to the default path because the installation directory is protected.

If that happens:

  1. choose to save the path somewhere else
  2. save it to a writable location
  3. 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.

Quick test

In the MATLAB command window, type:

spm

If SPM opens without an error, the path is working.


Step 4: Open CAT12 through SPM

After SPM opens:

  1. click Toolbox
  2. 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.


Step 5: Run segmentation on all structural scans

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.

Open the segmentation module

In CAT12:

  1. click Segment
  2. choose Volumes
  3. navigate to your copied VBM folder, not the shared original
  4. go to the top-level folder that contains both groups
  5. use a file filter such as nii.*
  6. use recursive selection so CAT12 searches through subfolders

What you should see

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

Run preprocessing

After all expected files are selected:

  1. click Done
  2. confirm the file list looks correct
  3. click Run

CAT12 will then process each subject.


Step 6: Wait for preprocessing to finish

CAT12 preprocessing takes time. Do not assume it is finished just because MATLAB is still open.

How to monitor progress

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.


Step 7: Check which subjects finished successfully

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.

How to tell whether a subject finished

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.

What failed output often looks like

A failed subject may have:

  • only a few files in the anat folder
  • no CAT report

Practical rule

Do not move on to group-level statistics until you know exactly which subjects finished and which did not.


Step 8: Reprocess any failed subjects

If all subjects completed successfully, skip this step.

If some subjects failed, identify the incomplete cases and rerun only those subjects.

How to identify missing subjects

You can do this in either of two ways:

  1. inspect subject folders one by one for missing CAT reports
  2. 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
done

This command assumes:

  • your group folders are named Con and Sz
  • subject folders are named like sub-001

If your folder names differ, update the command accordingly.

Reprocessing workflow

To rerun failed cases:

  1. go back to CAT12 > Segment > Volumes
  2. select only the failed subject scans
  3. run segmentation again

Repeat until all intended subjects finish successfully.


Step 9: Smooth the gray matter images

After preprocessing is complete, the next step is to smooth the gray matter images.

Why smoothing matters

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.

How to smooth the images in SPM12

Check the video and here if you have any questions about the smoothing process.

In the SPM12 GUI:

  1. click Smooth
  2. double-click Images to smooth
  3. navigate to your CAT12_Tutorial directory
  4. enter mwp1 in the Filter field
  5. click Rec to recursively find the files
  6. once the images are loaded, click Done
  7. keep the default smoothing kernel at [8 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].

What to check

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.


Step 10: Extract total intracranial volume (TIV)

Once preprocessing is complete, extract total intracranial volume (TIV).

Why TIV matters

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.

How to extract TIV in CAT12

From the CAT12 window:

  1. choose the option to get total intracranial volume
  2. point CAT12 to the processed subject output files
  3. 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

What to check

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.


Step 11: Set up the second-level group model

After preprocessing, smoothing, and TIV extraction are complete, you are ready to build the group-level model.

Two ways to set up the group analysis

You have two options for setting up a group-level analysis:

  1. click Basic Models in the CAT12 GUI
  2. 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.

Create the second-level output directory

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 2ndLevel

This directory will store the design matrix and model outputs for the group analysis.

Open Basic Models and set the output directory

In the CAT12 GUI:

  1. click Basic Models
  2. double-click Directory
  3. select the new folder you just created: 2ndLevel

Define the factor

Under Factors:

  1. change the Name to Group
  2. set the number of Levels to 2

This creates a two-group design.

Create the group cells

Under Cells:

  1. click New: Cell
  2. for the first cell, click Levels and enter 1
  3. double-click Scans
  4. navigate to the Con directory
  5. in the Filter field, type smwp1
  6. click Rec
  7. click Done

Then repeat the same process for the second group:

  1. click New: Cell
  2. set Levels to 2
  3. double-click Scans
  4. navigate to the Sz directory
  5. in the Filter field, type smwp1
  6. click Rec
  7. click Done

This assigns the smoothed gray matter maps for the Con group to level 1 and the Sz group to level 2.

Add TIV as a covariate

In the Covariates field:

  1. select New: Covariate
  2. double-click Name and enter TIV
  3. double-click Vector
  4. copy and paste the values from the TIV.txt file you generated earlier

Leave the remaining covariate defaults unchanged.

Check design orthogonality and homogeneity

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.

Add model estimation to the same batch

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:

  1. click the new Model Estimation module
  2. highlight the Select SPM.mat field
  3. click Dependency in the lower-right corner of the Batch Editor
  4. select the SPM.mat dependency from the Factorial design specification module

This tells SPM to estimate the model that you just specified in the previous step.


Step 12: Define contrasts and run the batch

After adding the model estimation step, add the contrast manager so the design, estimation, and contrasts can all be run in one batch.

Add the Contrast Manager

In the Batch Editor menu, click:

SPM -> Stats -> Contrast Manager

This adds a Contrast Manager module to the batch.

Then:

  1. click the Contrast Manager module
  2. highlight the Select SPM.mat field
  3. click Dependency
  4. select the SPM.mat file from the Model Estimation step

This links the contrast manager to the model that was just estimated.

Define the group contrasts

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.

Contrast 1: Con > 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.

Contrast 2: Sz > Con

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.

Run the full batch

Once everything is connected:

  1. review the batch carefully
  2. confirm that the correct scans are in each group
  3. confirm that the TIV values are in the correct subject order
  4. click the green Go button

SPM/CAT12 will then:

  1. specify the factorial design
  2. check design orthogonality and homogeneity
  3. estimate the model
  4. generate the contrasts

After the batch finishes, you can move on to reviewing the statistical results.


Step 13: Review the results carefully

Once the model is estimated and contrasts are run, review the statistical maps and tables carefully.

At minimum, check the following

  • 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

Important caution

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.


Recommended beginner checklist

Use this checklist before trusting your results.

Data setup

  • 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 / SPM / CAT12 setup

  • MATLAB launched successfully.
  • SPM12 opens when I type spm.
  • CAT12 appears in the SPM toolbox menu.

Segmentation

  • I selected the correct .nii or .nii.gz files recursively.
  • The total number of selected files matches what I expected.
  • CAT12 finished processing all intended subjects.
  • Each completed subject has a CAT report.

Reprocessing

  • Any failed subjects were identified.
  • Failed subjects were rerun until complete.

TIV and statistics

  • 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.

Common problems and fixes

Problem 1: SPM does not open

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.

Problem 2: CAT12 is missing from the toolbox

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.

Problem 3: CAT12 does not find all expected MRI files

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.

Problem 4: Some subjects do not finish processing

Cause: CAT12 preprocessing failed for those cases.

Fix: Look for missing CAT reports, identify the failed subjects, and rerun segmentation on just those subjects.

Problem 5: MATLAB cannot save the path

Cause: You are trying to write to a protected location.

Fix: Save the path to your home directory or another writable location.

Problem 6: MATLAB 2025b crashes or behaves unpredictably

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.


Plain-language summary

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.


Final advice

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.

What You Turn In

For this assignment, please upload a screenshot of the Matlab session showing some results.

Clone this wiki locally