Differences between revisions 1 and 26 (spanning 25 versions)
Revision 1 as of 2013-04-22 11:53:10
Size: 10960
Editor: EmmaBenAvi
Comment:
Revision 26 as of 2017-03-28 16:56:41
Size: 6304
Editor: AndrewHoopes
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
[[FsTutorial|top]] | [[FsTutorial/TroubleshootingData_freeview|previous]] [[FsTutorial|top]] | [[FsTutorial/TroubleshootingData|previous]]
Line 4: Line 4:
 * To follow this exercise exactly be sure you've downloaded the [[FsTutorial/Data|tutorial data set]] before you begin. If you choose not to download the data set you can follow these instructions on your own data, but you will have to substitute your own specific paths and subject names.  * To follow this exercise exactly, be sure you've downloaded the [[FsTutorial/Data|tutorial data set]] before you begin. If you choose not to download the data set you can follow these instructions on your own data, but you will have to substitute your own specific paths and subject names.
Line 6: Line 6:
Occasionally, the skull stripping step either removes more than just the skull, causing part of the brain to be removed as well, or too little, leaving behind portions of the skull. Both of these problems need to be corrected before continuing to the next step, either by manually editing the volumes or by adjusting input parameters to the skull stripping step, and running the skull strip again until a good result is obtained.  Often the sagittal view reveals skull strip failures.  Note that the inflated 2D surface is a less reliable gauge of skull strip failure unless large portions of the brain are missing, or lots of skull is retained. Occasionally, the skull stripping step either removes more than just the skull, causing part of the brain to be removed as well, or too little, leaving behind portions of the skull. In most cases, both of these problems need to be corrected before continuing to the next step, either by manually editing the volumes or by adjusting input parameters to the skull stripping step, and running the skull strip again until a good result is obtained. However, if portions of the skull are left behind but they do not affect the pial or white surface (as the image below suggests), this is not considered to be an error. The red arrow indicates a portion of dura and skull that were not removed during the skull stripping step.
Line 8: Line 8:
skullstrip1_before has a poor skull strip, an entire hemisphere of the cerebellum has been stripped away along with the skull. This page will walk you through the process of fixing this particular subject and also offer suggestions for fixing other common skull stripping problems. Often the sagittal view reveals skull strip failures. Note that the inflated 3D surface is a less reliable gauge of skull strip failure unless large portions of the brain are missing, or lots of skull is retained.
Line 10: Line 10:
If you look at coronal slice 91 for skullstrip1_before you can see that the brainmask.mgz volume (the first picture) is missing the right hemisphere of the cerebellum and that it is present in the T1.mgz volume (the second picture): {{attachment:skull_strip_dura.jpg||width="375",height="504"}}
Line 12: Line 12:
{{attachment:subj1_brainmask.jpg}} {{attachment:subj1_T1.jpg}} This page will walk you through the process of fixing a subject with a skull stripping problem. The subject below, skullstrip1_before, has a poor skull strip in which posterior regions of the cortex have been stripped away along with the skull.
Line 14: Line 14:
In general there are two ways to fix a volume when there is something missing from the cortex or cerebellum, you can clone the missing pieces in manually or you can adjust the parameters of mri_watershed to do it automatically. For this case, because there is such a lot missing on so many slices you should adjust the parameters of mri_watershed. {{{
freeview -v skullstrip1_before/mri/T1.mgz \
skullstrip1_before/mri/brainmask.mgz:colormap=heat:visible=false \
skullstrip1_before/mri/aseg+aparc.mgz \
-f skullstrip1_before/surf/lh.white:edgecolor=yellow \
skullstrip1_before/surf/lh.pial:edgecolor=red \
skullstrip1_before/surf/rh.white:edgecolor=yellow \
skullstrip1_before/surf/rh.pial:edgecolor=red
}}}
You can see that the segmentation and surfaces exclude some cortex in sagittal slice 101 (first image), and if you show the heat-mapped brainmask over the T1 volume (second image), you will see that these issues stem from a bad skull strip.

{{attachment:SkullStripFix_freeview.jpeg||height="350"}}

In general, there are two ways to fix a volume when there is something missing from the cortex or cerebellum - you can either clone in the missing pieces manually or adjust the parameters of mri_watershed to do it automatically. For this case, the easiest fix is to adjust the parameters of mri_watershed.
Line 17: Line 30:
The watershed algorithm is used during the skull stripping step to find a boundary between the brain and skull. The mri_watershed program uses a default preflooding height of 25 percent. If we want the algorithm to be more conservative (i.e. if part of the brain has been removed), you will want to make that number larger than 25. If you want the algorithm to be more aggressive (i.e. part of the skull has been left behind), you will want to make the height less than 25. There aren't any hard and fast rules about how to select your height value. You can adjust the preflooding height by passing the following flag to recon-all:

{{{recon-all -skullstrip -wsthresh <h> -clean-bm -subjid <subject name>}}} where <h> is replaced with the preflooding height you'd like to use and <subject name> is replaced with your subject. The clean-bm flag is used to instruct recon-all to write over the old brainmask.mgz volume with your new edits. If you do not use this flag your changes will not take effect.

'''Part of the brain is missing'''<<BR>> Now we will take another look at the first volume we looked at, where part of the cerebellum had been removed. If you suspect that certain anatomy could be an outlier, and may be responsible for making the skullstripping step fail or produce poor results then you can try using the -no-wsgcaatlas flag (wsgcaatlas = with skull gaussian classifier array atlas). You can adjust the watershed threshold by passing the -wsthresh flag to recon-all. In this instance, since too much was removed, we want to raise the watershed threshold so use the command:

----
{{{
recon-all -skullstrip -wsthresh 35 -clean-bm -no-wsgcaatlas -subjid skullstrip1_before
}}}
----
Take a look at your output volume (brainmask.mgz has been changed) along with the original T1 volume (T1.mgz), and verify the result of the new skull stripping is correct.

----
{{{
tkmedit skullstrip1_before brainmask.mgz -aux T1.mgz -surfs
}}}
----
It should look like this: <<BR>> {{attachment:subj1_bm_after.jpg}}

''' Some skull still remains''' <<BR>> Sometimes the skull strip will leave pieces of skull in the brainmask volume. Subject skullstrip2_before is an extreme example of this, it can be the case that there is just a bit of skull left. If that is the case with a subject in your own dataset you may want to try running recon-all -skullstrip first to see if that fixes the problem before trying the steps outlined below. If you are working with the tutorial data than you should proceed with the example commands below, do not run recon-all -skullstrip. Open skullstrip2_before to see what it looks like:

----
{{{
tkmedit skullstrip2_before brainmask.mgz
}}}
----
and you should see this:<<BR>> {{attachment:111_watershed_before.jpg}}

For this example, since there is so much skull remaining, we want to lower the watershed threshold, so you could use the command:

----
{{{
recon-all -skullstrip -wsthresh 5 -clean-bm -no-wsgcaatlas -subjid skullstrip2_before
}}}
----
Take a look at your output volume (brainmask.mgz has been changed) along with the original T1 volume (T1.mgz), and verify the result of the new skull stripping is correct.

----
{{{
tkmedit skullstrip2_before brainmask.mgz -aux T1.mgz -surfs
}}}
----
You can compare this to the brain volume in skullstrip2_after to see that your changes look the same.

''' Reprocessing the data''' <<BR>> If you make changes to the brainmask.mgz volume, you can re-start the recon-all process from this point by using the following command:
The watershed algorithm is used during the skull stripping step to find a boundary between the brain and skull. If you want the algorithm to be more conservative (i.e. if part of the brain has been removed), you will want to decrease the watershed preflooding height percentage, and if you want the algorithm to be more aggressive (i.e. part of the skull has been left behind), you will want to increase the height. You can adjust the preflooding height by passing the following flags to recon-all:
Line 65: Line 33:
recon-all -autorecon2 -autorecon3 -subjid <subject name> recon-all -skullstrip -wsthresh <h> -clean-bm -subjid <subject name>
Line 67: Line 35:
''' Trying Several Thresholds ''' <<BR>> If you would like to quickly run several different watershed thresholds simultaneously, you can use the -multistrip flag which will create several orig, T1, and nu volumes stripped with the following preflood heights: 5, 10, 20, 30. where <h> is replaced with the preflooding height you'd like to use and <subject name> is replaced with your subject. The clean-bm flag is used to instruct recon-all to write over the old brainmask.mgz volume with your new edits. If you do not use this flag, your changes will not take effect.
Line 69: Line 37:
You can change which preflood heights it uses (instead of 5, 10, 20, 30) by first doing: '''Part of the brain is missing'''<<BR>> Now we will take another look at the above problem case, where part of the cortex was removed. If you suspect that certain anatomy could be an outlier, and may be responsible for making the skullstripping step fail or produce poor results, then you can try using the -no-wsgcaatlas flag (wsgcaatlas = with skull gaussian classifier array atlas). For this case, try fixing the brainmask by running the watershed command with a few different preflooding heights between 1 and 50:
Line 72: Line 40:
setenv SUBJECTS_DIR /path/to/your/data
setenv WATERSHED_PREFLOOD_HEIGHTS '20 30 40 50'
recon-all -multistrip -clean-bm -s <subjid> -no-isrunning
recon-all -skullstrip -wsthresh <h> -clean-bm -no-wsgcaatlas -subjid skullstrip1_before
Line 76: Line 42:
Note that it will launch mri_watershed for each one for each vol orig, nu and T1, so if you have 12 heights, for example there will be 36 processes. Take a look at your output volume (brainmask.mgz has been changed) along with the original T1 volume (T1.mgz).

{{{
freeview -v skullstrip1_after/mri/T1.mgz \
skullstrip1_after/mri/brainmask.mgz:colormap=heat
}}}
The accurately skull-stripped brainmask should look something like this (sagittal slice 101):

{{attachment:SkullStripFix_freeview_002.jpeg||height="350"}}

What watershed threshold value did you use to produce an optimal skull strip? Was is between 20 and 30? If so, that's because the default preflooding height is 25, which produces the cleanest skull strip for most cases. There aren't any hard and fast rules about how to select your height value, but as a general rule of thumb, if part of the brain is missing, you should start with a watershed threshold around 35, and if too much skull is remaining, you should start with a threshold of around 15.
Line 82: Line 58:
recon-all -skullstrip -clean-bm -gcut -subjid <subjid> recon-all -skullstrip -clean-bm -gcut -subjid <subject name>
Line 84: Line 60:
INFO: Care must be taken to thoroughly inspect your data when using -gcut. In particular, inpsect the edges of gm and cerebellum for over-aggressive cutting. Add -segmentation brainmask.gcuts.mgz to tkmedit to view the voxels which gcut has removed. We recommend viewing the brainmask.gcuts.mgz overlayed on the T1.mgz to clearly see which voxels have been removed by gcut. INFO: Care must be taken to thoroughly inspect your data when using -gcut. In particular, inspect the edges of gm and cerebellum for over-aggressive cutting. Open the brainmask.gcuts.mgz volume in freeview to view the voxels which gcut has removed. We recommend viewing the brainmask.gcuts.mgz overlayed on the T1.mgz to clearly see which voxels have been removed by gcut.
Line 86: Line 62:
{{attachment:brainmask_gcuts_sag.jpg||height="379px",width="434px"}} {{attachment:brainmask_gcuts_cor.jpg||height="379px",width="434px"}} {{attachment:brainmask_gcuts_axial.jpg||height="378px",width="431px"}} {{attachment:brainmask_gcuts_sag.jpg||width="434px",height="379px"}} {{attachment:brainmask_gcuts_cor.jpg||width="434px",height="379px"}} {{attachment:brainmask_gcuts_axial.jpg||width="431px",height="378px"}}
Line 88: Line 64:
== Use talairach_with_skull_2.lta ==
During the skull-strip stage, the registration file {{{talairach_with_skull.lta}}} is created by mri_em_register in order to make use of the atlas to find skull. But in the autorecon2 stage, the registration file {{{talairach_with_skull_2.lta}}} is created, and this one is created with the benefit of the mri_ca_register stage, and so tends to be a tiny bit more accurate than {{{talairach_with_skull.lta}}}, and so it is possible that the skull-strip will work better with this registration file. So to make use of it:
== Regenerating surfaces after the bad skull strip is fixed ==
After the bad skull strip has been improved, you can run the following command to regenerate Freesurfer output based on the new brainmask.mgz:
Line 92: Line 68:
cd $SUBJECTS_DIR/yoursubj/mri/transforms
cp talairach_with_skull.lta bak
cp talairach_with_skull_2.lta talairach_with_skull.lta
recon-all -s yoursubj -skullstrip -clean-bm -clean-lta
recon-all -autorecon-pial -subjid <subject name>
Line 97: Line 70:
Inspect the brainmask.mgz after this completes.

== Manual editing ==
When the skull stripping process has left just a few slices with either missing brain regions or too much skull you can edit these manually using tkmedit.

''' Part of the brain is missing''' Sometimes there will be small regions missing from the pons or cerebellum, or from part of the cortex itself. To fix these you'd need to open the output volume from the skull stripping step (brainmask.mgz) and the original T1 volume (T1.mgz) simultaneously.

'''For this following example we will use a subject with a missing cerebellum to demonstrate the tools, but in reality this is not an example of something you would want to edit by hand.'''

----
{{{
tkmedit skullstrip3_before brainmask.mgz -aux T1.mgz
}}}
----
Switch back and forth between the two volumes a few times with Ctrl-1 and Ctrl-2, and use the arrow keys to view the different slices. Notice that a large part of the cerebellum has been stripped away along with the skull around slice 91.

In the tkmedit toolbar, go to:

'''Tools -> Configure Volume Brush...'''

Set Mode to "Clone", and Clone Source to "Aux Volume". Click the Close button to close the configuration window. You can also change the size and shape of your brush, to do this go to:

'''Tools -> Configure Brush Info...'''

Select a radius and shape that you are comfortable using. Close the configuration menu, and click the "Edit Voxels" button in tkmedit toolbar.

Use Ctrl-1 and Ctrl-2 to cycle between the two volumes. Find a place in the image where the cerebellum is missing in the output volume, then use the middle button on the mouse to paint in cerebellum from the auxiliary volume. Cycle back and forth between the volumes frequently so you know where you are.

Continue painting until the slice is no longer missing part of the brain. Repeat for the other slices in the output volume. Go to '''File -> Save Main Volume As...''' and save your output.

''' Some skull still remains''' <<BR>> If there are small pieces of skull still remaining on only a few slices you can manually remove the voxels. To do this make sure that the "Edit Voxels" button is still selected. Removing voxels is very similar to painting in voxels, except you use the right mouse button instead of the middle button. Use Ctrl-1 and Ctrl-2 to cycle between the volumes. Find a place in the image where skull remains. Use the right mouse button to delete the voxels. Continue on the other slices until all skull is removed. Save your volume.

Ctrl-z and '''Edit -> Undo Last Edit''' in tkmedit only allow you to go back one edit. If you need to erase a mistake made when painting in voxels, you can use the right mouse button to delete them again. If you remove too many voxels, you can use the clone tool to paint areas back in from the original T1 volume, similar to painting in voxels as described above.
'''Do not run this command if you are conducting the tutorial!'''

top | previous

Fixing a bad skull strip

  • To follow this exercise exactly, be sure you've downloaded the tutorial data set before you begin. If you choose not to download the data set you can follow these instructions on your own data, but you will have to substitute your own specific paths and subject names.

Occasionally, the skull stripping step either removes more than just the skull, causing part of the brain to be removed as well, or too little, leaving behind portions of the skull. In most cases, both of these problems need to be corrected before continuing to the next step, either by manually editing the volumes or by adjusting input parameters to the skull stripping step, and running the skull strip again until a good result is obtained. However, if portions of the skull are left behind but they do not affect the pial or white surface (as the image below suggests), this is not considered to be an error. The red arrow indicates a portion of dura and skull that were not removed during the skull stripping step.

Often the sagittal view reveals skull strip failures. Note that the inflated 3D surface is a less reliable gauge of skull strip failure unless large portions of the brain are missing, or lots of skull is retained.

skull_strip_dura.jpg

This page will walk you through the process of fixing a subject with a skull stripping problem. The subject below, skullstrip1_before, has a poor skull strip in which posterior regions of the cortex have been stripped away along with the skull.

freeview -v skullstrip1_before/mri/T1.mgz \
skullstrip1_before/mri/brainmask.mgz:colormap=heat:visible=false \
skullstrip1_before/mri/aseg+aparc.mgz \
-f skullstrip1_before/surf/lh.white:edgecolor=yellow \
skullstrip1_before/surf/lh.pial:edgecolor=red \
skullstrip1_before/surf/rh.white:edgecolor=yellow \
skullstrip1_before/surf/rh.pial:edgecolor=red

You can see that the segmentation and surfaces exclude some cortex in sagittal slice 101 (first image), and if you show the heat-mapped brainmask over the T1 volume (second image), you will see that these issues stem from a bad skull strip.

SkullStripFix_freeview.jpeg

In general, there are two ways to fix a volume when there is something missing from the cortex or cerebellum - you can either clone in the missing pieces manually or adjust the parameters of mri_watershed to do it automatically. For this case, the easiest fix is to adjust the parameters of mri_watershed.

Adjusting watershed parameters

The watershed algorithm is used during the skull stripping step to find a boundary between the brain and skull. If you want the algorithm to be more conservative (i.e. if part of the brain has been removed), you will want to decrease the watershed preflooding height percentage, and if you want the algorithm to be more aggressive (i.e. part of the skull has been left behind), you will want to increase the height. You can adjust the preflooding height by passing the following flags to recon-all:

recon-all -skullstrip -wsthresh <h> -clean-bm -subjid <subject name>

where <h> is replaced with the preflooding height you'd like to use and <subject name> is replaced with your subject. The clean-bm flag is used to instruct recon-all to write over the old brainmask.mgz volume with your new edits. If you do not use this flag, your changes will not take effect.

Part of the brain is missing
Now we will take another look at the above problem case, where part of the cortex was removed. If you suspect that certain anatomy could be an outlier, and may be responsible for making the skullstripping step fail or produce poor results, then you can try using the -no-wsgcaatlas flag (wsgcaatlas = with skull gaussian classifier array atlas). For this case, try fixing the brainmask by running the watershed command with a few different preflooding heights between 1 and 50:

recon-all -skullstrip -wsthresh <h> -clean-bm -no-wsgcaatlas -subjid skullstrip1_before

Take a look at your output volume (brainmask.mgz has been changed) along with the original T1 volume (T1.mgz).

freeview -v skullstrip1_after/mri/T1.mgz \
skullstrip1_after/mri/brainmask.mgz:colormap=heat

The accurately skull-stripped brainmask should look something like this (sagittal slice 101):

SkullStripFix_freeview_002.jpeg

What watershed threshold value did you use to produce an optimal skull strip? Was is between 20 and 30? If so, that's because the default preflooding height is 25, which produces the cleanest skull strip for most cases. There aren't any hard and fast rules about how to select your height value, but as a general rule of thumb, if part of the brain is missing, you should start with a watershed threshold around 35, and if too much skull is remaining, you should start with a threshold of around 15.

Using gcut

When the skull stripping has left a small part of dura left, it is quicker to try and rerun the skullstrip step using the -gcut flag than to do manual editing. This flag removes any extra dura that could influence the surfaces.

recon-all -skullstrip -clean-bm -gcut -subjid <subject name>

INFO: Care must be taken to thoroughly inspect your data when using -gcut. In particular, inspect the edges of gm and cerebellum for over-aggressive cutting. Open the brainmask.gcuts.mgz volume in freeview to view the voxels which gcut has removed. We recommend viewing the brainmask.gcuts.mgz overlayed on the T1.mgz to clearly see which voxels have been removed by gcut.

brainmask_gcuts_sag.jpg brainmask_gcuts_cor.jpg brainmask_gcuts_axial.jpg

Regenerating surfaces after the bad skull strip is fixed

After the bad skull strip has been improved, you can run the following command to regenerate Freesurfer output based on the new brainmask.mgz:

recon-all -autorecon-pial -subjid <subject name>

Do not run this command if you are conducting the tutorial!

FsTutorial/SkullStripFix_freeview (last edited 2017-03-28 16:56:41 by AndrewHoopes)