Introduction/Overview
(1) Image math is similar across different processing programsβ¦though the syntax varies.
(2) I focus on FSL because I find it gives me more control over data types than SPM does (probably a reflection of how Matlab works), and I find the AFNI syntax much more cumbersome.
(3) I'll talk about why a particular statistical or mathematical process would be useful, and then show you how to implement it. Mostly, I focus on two command-line tools:
- fslstats can extract descriptive statistics from an image or the masked portion of an image.
- fslmaths can add, subtract, and multiply images (in addition to other mathematical functions).
β FSLstats
β FSLmaths
You may wish to download FSL Image Math and Stats_Utilities: This is a PDF based on the video presentation.
Watch this 6-minute video clip
After you run processing and analysis, you are left with at least two kinds of images. These will be our primary focus:
- statistical (with continuous values)
- masks (which should contain only 0's and 1's) are often extracted from atlases or may be drawn freehand.
β 03:49 Masks vs Statistical Images
β 04:52 Filename extensions in FSL
FSLstats
FSLstats allows you to extract simple descriptive statistics (e.g., mean, standard deviation, volume, min, and max) from your image. There's more than what I show you here, and the tools are flexible, but this should give you an idea of how it works and why such measurements are useful.
Watch this 13-minute video clip
β 00:18 Mean Intensity in a Masked Region
β 2:00 Other Descriptive Statistics
β 03:36 Volume
β 05:30 Range (Min, Max)
β 06:39 Max Location
β 07:09 Confirm a Mask is Binary
β 09:30 4D data
β 11:54 Summary
FSLmaths
In addition to extracting descriptive statistics with fslstats, you can perform image math with fslmaths. Image math can be used for thresholding, dilation, erosion, hole filling, removing NaNs, creating spherical or box-shaped rois, dimensionality reduction, and more. Let's look at some examples of when you might want to use such functions.
Watch this 18-minute video clip
β 00:53 Create (or fix) a nonbinary mask
β 04:38 Hotspot images
β 07:47 fsladd
β 08:26 Multiply images
β 09:05 Brain Extraction
β 11:26 Grey Matter Activations
β 13:35 Inverse mask with -binv
β 14:53 Thresholding
β 16:05 Combine operations
FSL Maths for Mask Cleanup
Sometimes you'll draw a freeform mask. This is common for researchers that study brain damage.Freeform mask sare often riddled with unintentional freckles, spikes, and holes. FSLmaths offers several tools that can help you to clean up these problems.
- For example, if you dilate a mask, it will often fill in small holes, and those won't come back when you erode it!
- When you erode a mask, very small freckles on the image will disappear, and they won't come back when you dilate it!
- There is even a special flag, -fillh, that will fill small holes in a mask.
Watch this 4.5-minute video clip
Summary
FSLstats can extract descriptive statistics about an image. FSLmaths can combine images for display or filter the values. FSL offers many more tools, and other packages, like AFNI and SPM also offer image utilities. See the References section below.
You can practice with these tools if you have an installation of FSL. FSL is installed on the U of A HPC for your convenience.
Watch this 2.5-minute video clip
Practice
Download the practice data to a machine with FSL installed and in the path.
wget https://osf.io/nmwk7/download -O fsl_utils_practice_data.zip
Stop and think about these concepts and terms
statistical image
4D image
Image Math
fsladd
fslstats
fslmaths
dilate
erode
fill holes
Resources
- FSL Image Math and Stats_Utilities: This is a PDF based on the video presentation.
- Bitbucket Scripts Various scripts I've written over the years, see the LIBRARY folder. Especially valuable scripts are described on Read the Docs:
- Grepper Troubled Tapir is my identifier and I've posted lots of examples of using FSL, fslstats, and fslmaths.
- Lesion Masks: Tips and Tools
- Neuroimaging Software on the HPC This section describes the neuroimaging tools (including FSL) installed on the HPC and available for your use. It also describes the necessary configuration of your account that will allow you to access the tools.
- A Practice Lesson is also available: FSL Utilities: Practice