psyc410_s2x:brain_extraction_segmentation
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
psyc410_s2x:brain_extraction_segmentation [2025/02/01 10:37] – [Part 4: Segmenting your skull-stripped brain automatically using FSL/FAST.] admin | psyc410_s2x:brain_extraction_segmentation [2025/02/01 11:24] (current) – removed admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | <WRAP centeralign> | ||
- | <typo ff:' | ||
- | Lab 4: Brain Extraction & Segmentation </ | ||
- | </ | ||
- | |||
- | ====== Information, | ||
- | |||
- | |||
- | ===== 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 ===== | ||
- | * [[https:// | ||
- | * [[https:// | ||
- | * FSL and the [[https:// | ||
- | * FSL and the [[https:// | ||
- | |||
- | |||
- | ===== Laboratory Report ===== | ||
- | |||
- | <WRAP center round important 100%> | ||
- | <WRAP centeralign> | ||
- | </ | ||
- | |||
- | ===== Housekeeping ===== | ||
- | <WRAP center round info 90%> | ||
- | The data that we will use throughout the semester is located in a directory on your Desktop: ''/ | ||
- | * <wrap em>Do not write output to the / | ||
- | </ | ||
- | |||
- | **1.** Create the output directory for tonight' | ||
- | <code bash> | ||
- | mkdir ~/ | ||
- | </ | ||
- | |||
- | <WRAP center round alert 90%> | ||
- | 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 **~/ | ||
- | * Use meaningful names for your directories //and// files! | ||
- | * You can create other subdirectories within each lab directory to keep your labs organized | ||
- | * e.g., '' | ||
- | </ | ||
- | |||
- | /* | ||
- | **1.** In our [[psyc410_s2x: | ||
- | |||
- | {{: | ||
- | |||
- | **2.** Modify your hidden bash files. | ||
- | * It's okay if you don't know what this means, just copy and paste the entire block of code below into your Terminal and press '' | ||
- | |||
- | < | ||
- | cat <<EOT >> ~/.bashrc | ||
- | ### FSL STUFF ### | ||
- | FSLDIR=/ | ||
- | . ${FSLDIR}/ | ||
- | PATH=${FSLDIR}/ | ||
- | export FSLDIR PATH | ||
- | EOT | ||
- | </ | ||
- | |||
- | * Then do it again with the this block of code | ||
- | |||
- | < | ||
- | cat <<EOT >> ~/ | ||
- | # FSL Setup | ||
- | FSLDIR=/ | ||
- | PATH=${FSLDIR}/ | ||
- | export FSLDIR PATH | ||
- | . ${FSLDIR}/ | ||
- | EOT | ||
- | </ | ||
- | |||
- | **3.** The data that we will use throughout the semester is located in a directory on your Desktop; ''/ | ||
- | * <wrap em>Do not write output to the / | ||
- | |||
- | <WRAP center round alert 80%> | ||
- | 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 **~/ | ||
- | * 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 / | ||
- | </ | ||
- | |||
- | <WRAP center round tip 80%> | ||
- | The unix (or OS X) file system uses the tilde character '' | ||
- | </ | ||
- | |||
- | |||
- | **2a.** [Do this step only if you __do__have the directory '' | ||
- | Delete the contents of ''/ | ||
- | * 1) the point-and-click way. Simply double click on '' | ||
- | * 2) The Unix way. **If you want to do things this way, please call me over to your computer so that I can ensure things looks correct //before// you hit '' | ||
- | * In your '' | ||
- | |||
- | **2b.** [Do this step if you __do not__ have the directory '' | ||
- | |||
- | * 1) Create your output directory | ||
- | <code bash> | ||
- | mkdir ~/ | ||
- | </ | ||
- | |||
- | |||
- | **4** Create the output directory for tonight' | ||
- | <code bash> | ||
- | mkdir ~/ | ||
- | </ | ||
- | |||
- | |||
- | **2.** Download and install [[https:// | ||
- | * Go to the [[https:// | ||
- | * Click on '' | ||
- | * Click on '' | ||
- | * The file will download into your '' | ||
- | * Double click on the '' | ||
- | * Drag and drop the '' | ||
- | * Alternatively, | ||
- | * '' | ||
- | |||
- | **3.** Download and install '' | ||
- | * Download software [[https:// | ||
- | * Double-click on the downloaded file '' | ||
- | * Double-click on the open box icon of '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * Enter the HNL password and click '' | ||
- | */ | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | ===== Data used in this lab ===== | ||
- | * MRI brain data is located in ''/ | ||
- | * For parts of the lab you will each work on a different brain. When I refer to your " | ||
- | |||
- | ^ Neuro Methods Neophyte | ||
- | | Angelia | ||
- | | Benji | subj06_1A.nii.gz | ||
- | | Blythe | ||
- | | Hollen | ||
- | | Mallory | ||
- | | Natalie | ||
- | | Norah | subj12_1A.nii.gz | ||
- | | Paula | subj13_1A.nii.gz | ||
- | | Ronan | subj21_1A.nii.gz | ||
- | | Stuart | ||
- | | Vaso | subj19_1A.nii.gz | ||
- | |||
- | <WRAP center round tip 70%> | ||
- | <WRAP centeralign> | ||
- | </ | ||
- | |||
- | |||
- | |||
- | ====== 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 '' | ||
- | |||
- | <WRAP center round info 70%> | ||
- | [[http:// | ||
- | </ | ||
- | |||
- | <WRAP center round tip 70%> | ||
- | The online manual for FSLeyes can be found [[https:// | ||
- | </ | ||
- | ===== 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. | ||
- | |||
- | <WRAP center round info 80%> | ||
- | You must use the command line to start FSL. Open a [[: | ||
- | </ | ||
- | |||
- | |||
- | <WRAP center round tip 80%> | ||
- | When running a program from the command line it is helpful to type ''&'' | ||
- | </ | ||
- | |||
- | The FSL GUI should appear after a few moments. For today' | ||
- | |||
- | {{ : | ||
- | |||
- | |||
- | |||
- | ===== Open FSLeyes ===== | ||
- | |||
- | **1.** Click on the '' | ||
- | |||
- | |||
- | {{ : | ||
- | |||
- | ===== Open Standard Brain ===== | ||
- | |||
- | To familiarize yourself with the viewer: | ||
- | |||
- | **1.** Click on '' | ||
- | |||
- | {{ : | ||
- | |||
- | **2.** Select the **' | ||
- | |||
- | {{ : | ||
- | |||
- | <WRAP center round info 80%> | ||
- | If your standard brain is fuzzier looking than the person next to you, you have likely opened up ' | ||
- | </ | ||
- | |||
- | <WRAP center round info 80%> | ||
- | 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' | ||
- | |||
- | For more information on the current usage of the MNI brain, [[http:// | ||
- | |||
- | |||
- | **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 '' | ||
- | * 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 [[https:// | ||
- | |||
- | |||
- | **5.** Close this file when you are done having fun and feel comfortable navigating around in FSLeyes (you are having fun...aren' | ||
- | |||
- | {{ : | ||
- | ===== Open Your Assigned Brain ===== | ||
- | |||
- | **1.** Click on '' | ||
- | |||
- | {{ : | ||
- | |||
- | **2.** The file selection window will default to a directory that we don't want. Jump to your desktop by selecting '' | ||
- | |||
- | **3.** Select your [[#Data used in this lab|assigned brain]] from the list and click open | ||
- | |||
- | **4.** In [[#Part 3: Skull stripping your test brain using FSL/ | ||
- | |||
- | <WRAP center round important 100%> | ||
- | <WRAP centeralign>< | ||
- | 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 '' | ||
- | * 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 '' | ||
- | |||
- | **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 '' | ||
- | |||
- | {{ : | ||
- | |||
- | 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. | ||
- | |||
- | <WRAP center round important 100%> | ||
- | <WRAP centeralign>< | ||
- | 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, | ||
- | |||
- | |||
- | |||
- | |||
- | <WRAP center round info 70%> | ||
- | If you previously closed FSL, [[#Opening FSL|reopen it]] to start a new session before continuing. | ||
- | </ | ||
- | |||
- | ===== BET - brain extraction tool ===== | ||
- | |||
- | <WRAP center round tip 60%> | ||
- | The online manual for the Brain Extraction Tool can be found [[https:// | ||
- | </ | ||
- | |||
- | ===== Skull Strip Your Brain ===== | ||
- | |||
- | **1.** Launch BET by selecting the '' | ||
- | |||
- | {{ : | ||
- | |||
- | **2.** Your '' | ||
- | * Click on the folder icon at the end of the '' | ||
- | * To go up on level in the directory hierarchy, double-click on the '' | ||
- | |||
- | **3.** You will also need to specify an '' | ||
- | |||
- | <WRAP center round alert 80%> | ||
- | 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 ''/ | ||
- | * In the '' | ||
- | |||
- | <WRAP center round tip 100%> | ||
- | It's often easiest to simply append " | ||
- | |||
- | So if my assigned brain were '' | ||
- | |||
- | But remember to specify the correct directory too. So the '' | ||
- | </ | ||
- | |||
- | <WRAP center round alert 90%> | ||
- | 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 ' | ||
- | |||
- | {{ : | ||
- | |||
- | **4.** Click '' | ||
- | |||
- | <WRAP center round tip 80%> | ||
- | Rather than selecting '' | ||
- | </ | ||
- | |||
- | ===== 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 [[#Open Your Assigned Brain|this earlier section of the lab]]. | ||
- | |||
- | **1.** In the FSLeyes window select '' | ||
- | |||
- | <WRAP center round alert 90%> | ||
- | When you go to add your skull stripped brain, FSLeyes might default to the '' | ||
- | </ | ||
- | |||
- | |||
- | <WRAP center round info 90%> | ||
- | You can load many different brains into FSLeyes simultaneously (as long as they' | ||
- | |||
- | {{ : | ||
- | |||
- | |||
- | 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 '' | ||
- | |||
- | |||
- | {{ : | ||
- | |||
- | * 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. | ||
- | |||
- | <WRAP center round tip 80%> | ||
- | Remember, you can click the ' | ||
- | </ | ||
- | |||
- | * 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 <wrap em> | ||
- | * 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 '' | ||
- | |||
- | <WRAP center round tip 100%> | ||
- | When you change the FIT value, make sure to **change your output filename**. If you run '' | ||
- | </ | ||
- | |||
- | |||
- | <WRAP center round alert 80%> | ||
- | Remember the name you gave to your best skull-stripped brain, as we will use this for the next part. | ||
- | </ | ||
- | |||
- | <WRAP center round important 100%> | ||
- | <WRAP centeralign>< | ||
- | * 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. __**F**__SL' | ||
- | |||
- | <WRAP center round tip 60%> | ||
- | The online manual for the FSL FAST tool can be found [[https:// | ||
- | </ | ||
- | |||
- | ===== Setup FAST ===== | ||
- | |||
- | **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 you've done before). | ||
- | |||
- | <WRAP center round tip 100%> | ||
- | I recommend first entering the folder in which your skull stripped brain lives (''/ | ||
- | </ | ||
- | |||
- | {{ : | ||
- | |||
- | **3.** You need to provide an '' | ||
- | |||
- | **4.**You should also choose the '' | ||
- | |||
- | <WRAP center round help 100%> | ||
- | <wrap centeralign> | ||
- | |||
- | 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 '' | ||
- | |||
- | {{ : | ||
- | </ | ||
- | |||
- | |||
- | <WRAP center round info 100%> | ||
- | 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 '' | ||
- | |||
- | {{ : | ||
- | </ | ||
- | |||
- | ===== Run FAST ===== | ||
- | |||
- | **5.** Start your segmentation by clicking '' | ||
- | |||
- | <WRAP center round alert 80%> | ||
- | 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 '' | ||
- | |||
- | While you wait you should start to familiarize yourself with some of the [[: | ||
- | </ | ||
- | |||
- | 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 | ||
- | | pve_0 | CSF | | ||
- | | pve_1 | grey matter | ||
- | | pve_2 | white matter | ||
- | |||
- | <WRAP center round tip 60%> | ||
- | 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 | ||
- | </ | ||
- | |||
- | <WRAP center round important 100%> | ||
- | <WRAP centeralign>< | ||
- | * 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 [[#View Your Skull Stripped Brain|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 ' | ||
- | |||
- | <WRAP center round tip 60%> | ||
- | Think back to the voxel in which we had gray matter (50%), white matter (20%), and CSF (30%). The '' | ||
- | </ | ||
- | |||
- | 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 '' | ||
- | * The '' | ||
- | * The '' | ||
- | * The '' | ||
- | * The '' | ||
- | |||
- | <WRAP center round info 80%> | ||
- | 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 '' | ||
- | </ | ||
- | |||
- | |||
- | 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; [[#Part 1a: Viewing MRI images in FSLeyes|FSLeyes]] for 2D " | ||
- | |||
- | <WRAP center round important 100%> | ||
- | <WRAP centeralign>< | ||
- | * 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; | ||
- | * 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. | ||
- | |||
- | - Hippocampus | ||
- | - Amygdala | ||
- | - Head of caudate | ||
- | - Thalamus | ||
- | - Orbital frontal cortex | ||
- | - Superior frontal gyrus | ||
- | - Middle temporal gyrus | ||
- | - Superior colliculi | ||
- | - Splenium of the corpus callosum | ||
- | - 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 [[: | ||
- | </ | ||
psyc410_s2x/brain_extraction_segmentation.1738424221.txt.gz · Last modified: 2025/02/01 10:37 by admin