Using FSL

Post date: Dec 9, 2012 3:05:14 AM

Reorient the brain to match with the orientation of the standard template images (MNI152).

fslreorient2std input_volume output_volume

The command just simply applies 90, 180 or 270 orientation to the input image, but does not register the input brain to match with the standard template.

Extract only the brain from the original volume

bet input_volume output_volume -R 

Shown in the figure below: the input volume (grey-scale color) might contain the whole scan, but after applying bet, only the brain (red) is kept.

How does MNI152 standard template looks like?

The NMI volume contains the integer labels, voxels with the same label are in the same ROI. The shape of the MNI volume can be seen as the "average volume" of human brains. Therefore, when we want to compare brains, it is a good idea to convert them into the (MNI) standard space first.

Convert from T1 space to MNI standard space

Let's assume we have the transformation in the form of MNI = T1_to_MNI*T1, that is, T1_to_MNI is a transformation matrix mapping from T1 space to the MNI space. This process registers the input file to the reference file (in this case, MNI_volume) and output the transformation matrix.

flirt -in T1_brain -ref MNI_volume -out MNI_brain -omat T1_to_MNI.mat

...and it takes a few minutes to run. The transformation matrix T1_to_MNI.mat looks like:

1.1699161  0.04791712901  0.03691943319  -8.83006597  
-0.05939760277  1.080974787  0.2649180215  -39.16254549  
-0.0135687962  -0.2967126174  1.098118937  -21.52232117  
0  0  0  1  

The brain after converted into the MNI space is shown below with the MNI label overlaid on top.

Now, you might want to show the ROI labels in the original T1 space of the brain volume.

Convert from MNI space into the original T1 space

The process is intuitive T1 = MNI_to_T1*MNI, where MNI_to_T1 = inv(T1_to_MNI). The transformation matrix MNI_to_T1 can be calculated using the command:

convert_xfm -omat MNI_to_T1.mat -inverse T1_to_MNI.mat

the inverse matrix MNI_to_T1 is

0.8523758329  -0.04281477092  -0.01832845927  5.455328435  
0.04150678346  0.8655520316  -0.2102074109  29.73957704  
0.02174746243  0.2333438166  0.8536234848  27.70232816  
0  0  0  1  

Now, let's say we have an ROI file called myROI_in_MNI volume (of course, in MNI space), and we want to map the volume into the T1 space. So, we will just apply MNI_to_T1 to the myROI_in_MNI volume:

flirt -in myROI_in_MNI.nii -ref T1_struc_bet -out myROI_in_T1 -applyxfm -init MNI_to_T1.mat

then we view myROI volume overlaid on the T1 volume as shown below:

Did you spot something strange on the ROI boundaries? Yes, such artifacts are caused by the default interpolation "trilinear" which averages the voxels at the boundaries resulting in non-integer values. Therefore, for ROI, we might want to restrict the interpolation algorithm to "nearest neighbor" which conserve the voxel value to integer:

flirt -in myROI_in_MNI.nii -ref T1_struc_bet -out myROI_in_T1 -applyxfm -init MNI_to_T1.mat -interp nearestneighbour

and a nicer result is shown below:

Now you might have a question "how can we pick only some regions of the brain as our ROI?"

How to make an ROI file from the ROI in the MNI standard template?

Here we use a bit of MATLAB code to make ROI nifti file. Please download the simple and self-explanatory MATLAB code here.

How to extract the whole-brain from bold fMRI data?

Let's say we have

anat.nii.gz // the T1 brain structural image and
bold.nii.gz // the bold fMRI signal

We first extract the whole-brain out of the whole scan, then we register the anat_bet to bold_bet and obtain the transformation matrix T1_to_fmri. To get the whole-brain out from bold we need to slice out one time-volume (one time-stamp in the time series) out of bold.nii.gz as bold itself is a time series.

Here are the details

0) We might want to check the information of the files by using

fslinfo anat.nii.gz

and the output might look like the following:

data_type      INT16
dim1           124
dim2           256
dim3           256
dim4           1
datatype       4
pixdim1        1.2000000477
pixdim2        0.9375000000
pixdim3        0.9375000000
pixdim4        1.0000000000
cal_max        490.0000
cal_min        0.0000
file_type      NIFTI-1+

and for bold.nii.gz, it might look like

data_type      INT16
dim1           40
dim2           64
dim3           64
dim4           1452
datatype       4
pixdim1        3.5000000000
pixdim2        3.7500000000
pixdim3        3.7500000000
pixdim4        2.5000000000
cal_max        2753.0000
cal_min        0.0000
file_type      NIFTI-1+

1) We extract a time-volume (time stamp) out of the bold.nii.gz using the command

fslsplit

However, the command would split all 1452 volume if you don't stop the operation!!! So, in my case, I press Ctrl+c to cancel the operation when I get to approximately 30 volumes.

fslsplit bold bold_t -t

which gives lots of output files

bold_t0001.nii.gz - bold_t1452.nii.gz

I just interrupt the run, stop and use bold_t0081.nii.gz as the representative of the bold data. Let's rename bold_t0018 to bold_t. Note that it's not very safe to use the early time volume.

Yet, I have a better solution that is more suitable for automatic process. We can just average the image across time axis. So, we use the command.

fslmaths bold -Tmean bold_t

I like this solution better.

2) extract the whole-brain from anat and bold_t using command

bet anat anat_bet -R 
bet bold_t bold_t_bet -R

Each will take around 30 seconds.

3) Now we will transform the anat_bet into the bold fmri space (which is much less resolution), using command

flirt -in anat_bet -ref bold_t_bet -out anat_bet_inbold -omat anat_to_bold.mat

This will take about 30 seconds. The operation means that you want to transform/register anat_bet (input volume) into the reference volume bold_t_bet, and save the output file to anat_bet_inbold, and save the output transformation matrix (from anat to bold) into anat_to_bold.mat(rix).

The figure below shows the data in each process.

T1-bet
T1-bet registered in bold space

The T1 structural brain image contains much more details than in bold-fmri.

The registered T1 brain image into the bold-fmri space. The boundary is clearer than that of bold-fmri image. We will use this as the whole-brain mask.

This is one time-volume sliced from the bold 4D signal. The resolution is not very good, hence hard to extract whole brain.

bold fmri

4) You might want to "binarize" the brain image, that is, convert voxels that >0 to 1. This process gives you the binary mask file for the whole brain. The command is

fslmaths anat_bet_inbold -thr 0 -bin mask_wb

which first threshold the image with 0 (discard all voxels whose value is less than 0), then binarize the image. The output image is stored in mask_wb.nii.gz.

Congratulations! Now you have the whole brain mask for bold fmri space.

Q: You may wonder why can't we just use the bold_t_bet as the whole-brain mask in the first place?

A: Good question! The answer is that it is more accurate to obtain the whole-brain mask in T1-space, and transform/downsample to the bold-fmri space.

Q: Why do we care about the transformation matrix anat_to_bold.mat?

A: Because this can be used when we want to plot our analysis results back into T1-space which looks better!

Resources

Visit FSL course webpage, FSL utilities and FSL registration tools for more details about the FSL.

Here is another good FSL tutorial from UT Austin ImageLab.