User Tools

Site Tools


psyc410_s2x:brain_extraction_segmentation

This is an old revision of the document!


Lab 4: Brain Extraction & Segmentation

Information, Preparation, Resources, Etc.

Assigned Readings / Videos:

Goals for this lab:

  • You will gain familiarity with image viewers and other software tools we will use throughout the semester.
  • You will learn to use software that masks the brain and strips the skull.
  • You will understand how the intensity of voxels can be related to different brain tissue types.
  • You will examine brain images in 2 dimensional views and create 3 dimensional volume renderings.
  • You will search for anatomical brain regions using these software tools.

Software introduced in this lab

Laboratory Report

This lab report will be due on Wednesday, Feb 5th by 7pm

Housekeeping

The data that we will use throughout the semester is located in a directory on your Desktop: /Users/hnl/Desktop/class/input

  • Do not write output to the /Users/hnl/Desktop/class/input directory or any of its sub-directories!

1. Create the output directory for tonight's lab.

mkdir ~/Desktop/output/lab04

It is important that you adhere to an organized system of directories and sub-directories for the labs. We will be creating lots and lots of files. Without an effort to keep organized you will quickly create a chaotic mess of files and have trouble finding and using what you need.

  • Your results should be stored in ~/Desktop/class/output/lab04 (or, lab05, lab06, etc.)
  • Use meaningful names for your directories and files!
  • You can create other subdirectories within each lab directory to keep your labs organized
    • e.g., mkdir /class/output/lab04/segment

Data used in this lab

  • MRI brain data is located in /Users/hnl/Desktop/class/input/mri/mri_retest
  • For parts of the lab you will each work on a different brain. When I refer to your “assigned brain” I am referring to those listed below.
Neuro Methods Neophyte Assigned Brain
Angelia subj05_1A.nii.gz
Benji subj06_1A.nii.gz
Blythe subj07_1A.nii.gz
Hollen subj08_1A.nii.gz
Mallory subj25_1A.nii.gz
Natalie subj10_1A.nii.gz
Norah subj12_1A.nii.gz
Paula subj13_1A.nii.gz
Ronan subj21_1A.nii.gz
Stuart subj14_1A.nii.gz
Vaso subj19_1A.nii.gz

These brains should be pretty good, but if you have one that seems ugly or low quality, let me know and we'll assign you a different one.

Part 1: Viewing MRI images in FSLeyes

There are lots of different MRI viewer programs available. As you might expect they all have their own strengths and weaknesses. We will primarily be using the viewer that is built into the FSL software package; FSLeyes. In this section of the lab I just want you to get familiar with the this viewer and play around with some of the options.

FSL is a library of tools for analyzing MRI, DTI, and fMRI data. It is very popular due to the fact that it is both flexible, powerful, and relatively easy to use.

The online manual for FSLeyes can be found here.

Opening FSL

FSL can be executed using a graphical user interface (a GUI) or by typing commands to the terminal. We will use the GUI for most of our exercises, but you should be aware that the command line interface is helpful when writing your own analysis scripts.

You must use the command line to start FSL. Open a terminal window and type fsl &.

When running a program from the command line it is helpful to type & at the end. This will run the program in the background. Otherwise, the terminal window will be 'locked up' while the program runs.

The FSL GUI should appear after a few moments. For today's exercises we will use FSLeyes, BET, and the FAST segmentation tool.

Open FSLeyes

1. Click on the FSLeyes button at the bottom of the FSL menu.You should see the following window.

Open Standard Brain

To familiarize yourself with the viewer:

1. Click on FileAdd Standard

2. Select the 'MNI152_T1_1mm.nii.gz' image. Feel to choose any other brain image too. Note that 'MNI152_T1_1mm.nii.gz' includes both the brain and skull, whereas 'MNI152_T1_1mm_brain.nii.gz' is only the brain (the skull has been removed from the image).

If your standard brain is fuzzier looking than the person next to you, you have likely opened up 'MNI152lin_T1_1mm.nii.gz'. Go back to step 1 and open up the correct file.

MNI stands for the Montreal Neurological Institute. 152 brains were collected at the MNI and averaged together with a resolution of 1 mm. Since everyone has a different brain, we usually transform each person's brain into a standard brain image (like the MNI one) to allow us to present and compare results across studies.

For more information on the current usage of the MNI brain, see here.

3. Play around with this standard brain.

Location and Intensity. As you click around, observe the values in the lower-right corner of the screen (see image below).

  • In the Location box, each voxel is identified in a three-dimensional space by its x, y, and z position.
  • in the window to the right, the intensity of the selected voxel is displayed next to the coordinates.
    • This intensity is reported as an arbitrary unit (i.e., the number itself is meaningless)
    • Sometimes, the value represents a meaningful statistics such as a z-score.

4. Continue to play with different options to see what they do (you won't break anything). See the FSLeyes quick start page to learn what different buttons do.

5. Close this file when you are done having fun and feel comfortable navigating around in FSLeyes (you are having fun…aren't you!?)

Open Your Assigned Brain

1. Click on FileAdd from file

2. The file selection window will default to a directory that we don't want. Jump to your desktop by selecting Desktop in the left panel of the window (in the list of “Favorites:). Then click on the class –> input –> mri –> mri_retest directories and select your assigned file.

3. Select your assigned brain from the list and click open

4. In Part 3 of this lab We will remove teh skull (“skull strip”) this brain using the BET program. After we do, we'll want to use FSLeyes to compare our skull-stripped brain to the original brain, so you can minimize the window, but keep your assigned brain loaded in FSLeyes.

LAB REPORT Part 1

There are no questions for Part 1 of this lab

Part 2: Viewing MRI images in MRIcroGL

As noted above, different viewers have different strengths and weaknesses. In the last part you used FSLeyes to view the MNI standard brain and your assigned brain in 2D. MRIcroGL is particularly good at quickly rendering the brain in 3D. So let's use it to take a quick look at our assigned brain before we continue on to skull-stripping.

MRIcroGL 2D

1. Open the MRIcroGL program by clicking on the icon in your dock.

.

  • You should see something like the image below. (If instead you see a big block of Swiss cheese or a lego brick, don't worry)

2. Open your assigned brain by selecting File –> Open.

  • You should see your brain displayed in 2D similar to what we saw with FSLeyes.

MRIcroGL 3D

3. Let's now view this brain rendered in 3D. To do so, select Display –> Render from the menu bar.

4. Let's play around with MRIcroGL to get a feel for interacting with a brain rendered in 3D.

  • If you click on the brain and drag your mouse around you'll be able to rotate the brain.
  • You can zoom in and out by dragging your mouse while holding the right-click.
  • Try to make Cutout in the brain by manipulating the x, y, and z sliders in the cutout section (you'll need to press Near to get started.)

This 3D rendering is pretty cool. But one thing that you undoubtedly noticed is that the presence of the skull, scalp, and other non-brain tissue obscures the cortical surface of the brain. Indeed, many viewers (including FSLeyes) would render a useless blob if given a brain like this. So in the next section we'll improve things by stripping away all the non-brain stuff.

LAB REPORT Part 2

There are no questions for Part 2 of this lab

Part 3: Skull stripping your test brain using FSL/BET

When rendering a brain volume, the skull, and neck make it difficult to see brain anatomy in 3D. As we will learn, these brain coverings also make it difficult to coregister brains into a common coordinate system. Consequently, removing the skull from the brain is an important first step in many analyses. In this section we will use the FSL Brain Extraction Tool (BET) program to accomplish this.

If you previously closed FSL, reopen it to start a new session before continuing.

BET - brain extraction tool

The online manual for the Brain Extraction Tool can be found here.

Skull Strip Your Brain

1. Launch BET by selecting the BET brain extraction button on the FSL menu. You should now see the following window:

2. Your Input image should be the same assigned brain you used in the previous section.

  • Click on the folder icon at the end of the Input image line and use the file selection box to navigate to the file. Select the file and press Ok
    • To go up on level in the directory hierarchy, double-click on the .. under “Directories:”

3. You will also need to specify an Output image.

FSL will automatically generate an output filepath and filename for you after you select your input image, but you do NOT want to use this default.

  • Click on the folder icon at the end of the Output Image line and navigate to the /Users/hnl/Desktop/class/output/lab04 folder and select Ok.
  • In the Output image line add your filename to the end of the path.

It's often easiest to simply append “_brain” to the end of the original file (but in front of the nii.gz file extension.

So if my assigned brain were prof_mri_01A.nii.gz, then my output filename would be prof_mri_01A_brain.nii.gz.

But remember to specify the correct directory too. So the Output Image would be ~/Desktop/class/output/lab04/prof_mri_01A_brain.nii.gz

As I previously stated, it is important that you use sensical and consistent filenames and directories. If you do not stay organized you will quickly find yourself struggling to make sense of a chaotic mess of files!

There are MANY options for skull stripping. You are encouraged to experiment with the different settings to achieve the best brain extraction. However, you may want to start by choosing the 'Robust brain centre estimation (iterates BET several times)' option on the first drop down menu.

4. Click Go and BET will start stripping. This usually takes a minute or two. You know you are done when the depressed Go button pops out again. Don't be impatient and keep pressing Go, as FSL will dutifully run another instance of the program.

Rather than selecting Exit after BET is done running, you should keep the window open. In the next section you will inspect your skull stripped brain and you might find that you need to run BET again with slightly different settings. Leaving the window open will just make it a little easier on you because your Input and Output images are already selected.

Load Your Skull Stripped Brain

We will now view the skull stripped brain by superimposing it onto the non-stripped version that you already have loaded into FSLeyes from this earlier section of the lab.

1. In the FSLeyes window select File –> Add from file and then navigate to and select your skull stripped brain you just created.

When you go to add your skull stripped brain, FSLeyes might default to the input directory of your unstripped brain. There might be a stripped brain in that same directory with the filename you just used. But this is not yours! Be sure you load the file that you created in ~/Desktop/class/output/lab04.

You can load many different brains into FSLeyes simultaneously (as long as they're the same dimensions). The Overlay list window in the bottom left corner shows you all the files that you currently have loaded.

 Overlay list menu

The order of the brains in the overlay list is also the order that the brains are stacked on each other in the viewer. By default, the most recent brain that was loaded will be the one on top, but you can use the arrow button in the overlay list to rearrange them. You can also click on the eyeball icon to toggle whether a particular brain is displayed.

Before proceeding, make sure that you have both your original. brain and your skull stripped brain load. The skull stripped version should be on to of the original, and both should be visible (the eyeball icon should be blue).

2. Your skull stripped brain is now being displayed stacked on top of your original brain. But it's nearly impossible to tell them apart. To make it easier to distinguish between them, we'll colorize the skull stripped brain.

  • In Overlay list, click on your skull stripped brain so that the filename is highlighted.
  • Change the colorscale dropdown menu (the menu is pointed out between the arrows in the image below) from Greyscale to Green (or any other color you'd like!)

  • Now you can see your original MRI in greyscale, and the skull stripped version of that same MRI overlaid on top and colored Green (or whatever color you chose.)

Inspect the Quality of Your Skull Stripped Brain

High quality skull stripping is defined as successfully removing all of the non-brain features (e.g,. skull), while preserving all of the brain tissue. In other words, if you are too aggressive then you will successfully get rid of all the non-brain, but you'll also throw out some brain. If you are too conservative then you will retain all of the brain, but you'll also keep bits of non-brain. The goal is to be a neuroscience Goldilocks; you don't want to remove too much, you don't want to remove too little, you want to remove the amount that's just right.

1. Closely examine your skull stripped brain - does it conform to the edges of your original brain? That is, did the skull stripping remove everything outside of the brain while preserving the entire brain itself? Make sure to move your cursor around and inspect lots of different regions and boundaries of the brain.

Remember, you can click the 'eyeball' icon to turn a specific overlay on or off. In this way, you can look at your skull stripped brain in isolation, or superimposed upon the original brain.

  • If you observe that some of the brain was cut away along with the skull, then your skull stripping was too aggressive. If you can still see parts of the skull or other non-brain tissue (e.g., meninges) then your skull stripping was too conservative. We can adjust this by manipulating the Fractional intensity threshold option on the BET GUI.
    • Larger numbers cut away more brain.
    • Smaller numbers cut away less brain.
  • In the examples below I would not be satisfied with the results. (Remember, you can click on the images to see larger versions)
    • The image on the left (red overlay) was too aggressive and removed parts of the brain, specifically a large chunk of the frontal lobe.
      • I would therefore determine that the fractional intensity was too high, and run it again with a lower value.
    • The image on the left (blue overlay) was too conservative and left in areas outside of the brain.
      • I would therefore determine that the fractional intensity was too low, and run it again with a higher value.

2. Rerun BET with a different Fractional intensity threshold and then inspect the new results. Iterate this process until you are happy with your results. Tip: First try a large change in the Fractional intensity threshold, examine your result, and then split your original change in half, examine the new result, rinse and repeat.

When you change the FIT value, make sure to change your output filename. If you run subj99_1A_brain with a new fractional intensity threshold of .3, then name the output subj99_1A_brain_fit3.

Remember the name you gave to your best skull-stripped brain, as we will use this for the next part.

LAB REPORT Part 2

  • Create a figure showing your best brain extraction overlaid on your original brain.
    • Report the fractional intensity threshold that you used.
  • Create a second figure showing this same brain in MRIcroGL.

Part 4: Segmenting your skull-stripped brain automatically using FSL/FAST.

Segmentation is the process of segmenting different anatomical features (i.e., separating them), including grey matter, white matter, and cerebral spinal fluid. FAST is a program that attempts to do this automatically.

The online manual for the FSL FAST tool can be found here.

1. Go back to the FSL GUI and select FAST.

2. This will bring up another GUI in which you provide the name of your skull stripped brain as the Input Image (using the File Selection box as before).

I recommend first entering the folder in which your skull stripped brain lives (/Users/hnl/Desktop/class/output/lab03) and then clicking the folder icon to select the specific file.

3. You need to provide an output base name. The default is the name of your skull stripped brain - which is usually appropriate.

4.You should also choose the Estimated Bias Field option by clicking on its box.

Inhomogeneity of the magnetic field causes intensity variations across space (see the image from FSL below). This can screw up segmentation because the voxel intensities for different tissues will vary across the brain. In the image on the left below, compare the intensity of the white matter in the posterior region of the brain to the intensity of the white matter in the anterior region of the brain. The Estimated bias field option attempts to correct for this prior to tissue segmentation.

5. Start your segmentation by clicking Go

Tissue classification is an iterative, computer intensive process that takes about 5-7 minutes to complete on an unloaded system. You will know it has complted once the Go button no longer appears depressed.

While you wait you should start to familiarize yourself with some of the brain atlases and anatomy that you will need to complete the last section of this week's lab (right-click on the link and open in a separate tab so that you don't leave tonight's wiki page).

Once FAST is complete, you will have several additional files in your output folder. These include individual partial volume estimates for each tissue type where the voxel intensities represent (on a scale of 0 to 1) the estimated amount of each tissue type in each voxel.

File suffix Tissue type
pve_0 CSF
pve_1 grey matter
pve_2 white matter

Let's imagine a voxel in which we had gray matter (50%), white matter (20%), and CSF (30%). The partial volume estimates for this voxel would be pve_0 = .3, pve_1 = .5, and pve_2 = .2

LAB REPORT Part 3

  • Overlay each of these segmentation files onto your skull-stripped brain and assign them each a different color.
    • After doing so you should see all three tissue types superimposed on the same brain.
    • Refer back to the earlier section of the lab if you forgot how to do this.
  • Include this image in your lab report and include a key detailing which tissue type is represented by each color.

FAST also creates 'hard' segmentations (the file with _seg in the file name) where each voxel is labeled by predominate tissue type.

Think back to the voxel in which we had gray matter (50%), white matter (20%), and CSF (30%). The _seg file would assign this voxel a value of 1, because it has more grey matter than white matter or CSF.

In the example below I have loaded all three partial segmentation files as well as the hard segmentation file. Note the voxel values in the Location window.

  • The seg_pve_0 file = 0.0 indicating that FAST estimated the voxel indicated by the crosshairs does not include any CSF.
  • The seg_pve_1 file = 0.48 indicating that FAST estimated the voxel indicated by the crosshairs includes 48% grey matter.
  • The seg_pve_2 file = 0.52 indicating that FAST estimated the voxel indicated by the crosshairs includes 52% white matter.
  • The _seg = 2 indicating that the predominant tissue type in that voxel is greay matter.

You're right, this is confusing. Why would the hard segmentation indicate the voxel is grey matter if the program estimates that 52% is white matter? This type of inconsistency occasionally arrises because the partial volume estimates and the hard segmentation estimates rely on different algorithms. The hard segmentation takes into account the neighboring voxels. In this case most of them are grey matter, so the voxel is assigned as grey matter, even though the partial volume estimate is that it is only 48% grey matter.

Experiment with overlaying these results upon your original and skull stripped brain in FSLeyes.

Voxel intensity value Tissue type
0 Out of brain
1 Cerebrospinal fluid
2 Grey matter
3 White Matter

Part 5: Identify neuroanatomy using FSLeyes and MRIcroGL

We now have a pretty skull-stripped brain and two viewers to investigate them; FSLeyes for 2D “slices” and MRIcroGL for 3D renderings. Your final task is to use these tools to find several anatomical structures.

LAB REPORT Part 4

  • Use a combination of 2D and 3D views, find the following structures listed below. Use the view that you think works best for the particular structure. But don't choose arbitrarily; some structures are easy to see in 2D, whereas others are better viewed in 3D.
  • You only need a 2D or a 3D view for each structure
    • But include at least three 2D and at least three 3D images
  • Include a clearly labeled screenshot of each structure.
  1. Hippocampus
  2. Amygdala
  3. Head of caudate
  4. Thalamus
  5. Orbital frontal cortex
  6. Superior frontal gyrus
  7. Middle temporal gyrus
  8. Superior colliculi
  9. Splenium of the corpus callosum
  10. Pons

Tip: If you're not sure where these areas are in the brain you should take advantage of some online neuroanatomy atlases that can be found here. Feel free to exploit any resource you'd like to find the location of these structures.

psyc410_s2x/brain_extraction_segmentation.1738423371.txt.gz · Last modified: 2025/02/01 10:22 by admin

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki