Tuesday, November 20, 2012

A Note about FMRI Masks



Now that we have covered how to create masks using three separate software packages - FSL, SPM, and AFNI - I should probably take a step back and talk about what masks are all about. When I first read about masks, all I heard was a bunch of mumbo jumbo about zeros and ones, and unhelpful saran wrap metaphors. While this did remind me to purchase valuable kitchen supplies, it was unhelpful in understanding what a mask was, exactly, and how it was used.

Simply put, a mask is a subset of voxels you wish to analyze. Let's say I'm only interested in the right hemisphere of the brain; to create a mask of the right hemisphere, imagine using a papercutter to split the brain in half, and only taking the right hemisphere for further analysis, while discarding the left hemisphere into the trash can. The generation of masks follows this same logic - only focus on a specific part of the brain, and discard the rest.

Fortunately, we have come a long way since using office supplies to create masks, and now we have computers to do it for us. In order to create a mask using any of the listed software packages, usually you will use a tool to insert "1's" into the voxels that you wish to analyze, and "0's" everywhere else. Then, say that you want to do an ROI analysis only on those voxels that contain "1's". If you are trying to extract contrast estimates for a subject, the contrast estimate at each voxel will be multiplied by the mask, and you will be left with the contrast estimates in the "1's" voxels (since each estimate is being multiplied by 1), and zeros everywhere else.

Furthermore, ROI extraction within a mask often averages the contrast (or parameter) estimates across all of the voxels inside the mask. It is also possible to extract estimates from single voxels or a single triplet of coordinates - just think of this as ROI analysis of a very small mask.

I hope that this clarifies things a bit; I know that it took me a couple of years to wrap my head around the whole concept of masks and ROIs and severing hemispheres from each other. However, once you understand this, the whole process of ROI interrogation becomes much simpler and more intuitive, and analyses become easier to carry out. ROI analysis is the foundation for carrying out more complex analyses, such as double dissociations and connectivity analyses, and it is well to become familiar with this before tackling larger game.

27 comments:

  1. I am interested in activation in the amygdala to a response. Please could you explain the difference between doing an analysis using small volume correction (eg an amygdala 'mask') and using an amygdala mask to 'apply masking' in the results/analysis using SPM. I get different cluster statistics for the same cluster when I do either of these - but which is the correct way?
    thank you in advance,
    Anjie

    ReplyDelete
    Replies
    1. Hey Anjie,

      My understanding is that SVC looks for significant clusters within a restricted region, while masking allows you to extract parameter and contrast estimates averaged across the ROI - usually used in conjunction with Marsbar or spm_get_data. See my post here for more details: http://andysbrainblog.blogspot.com/2014/07/quick-and-efficient-roi-analysis-using.html


      Best,

      -Andy

      Delete
  2. Hey Andrew,
    In order to perform analysis on fMRI data, should we apply a complete mask on brain in order to separate useful brain voxels from background voxels(voxels which doesn't contain brain regions)?
    My question might be silly I'm sorry I'm new in fMRI!
    Thank you

    ReplyDelete
  3. Hey there,

    You can do either. One reason for keeping all the voxels - brain or not - during a first-level analysis is to observe whether there are any artifacts outside of the brain. In my experience you can usually detect these from looking at the raw EPIs, and I usually mask out all the non-brain voxels before doing a first-level analysis.


    Best,

    -Andy

    ReplyDelete
    Replies
    1. Hi Andrew,
      Do you have a tutorial explaining how to mask out the whole brain (in spm maybe)? And what stage do you do this (before or after preprocessing)? I'm currently analyzing functional connectivity z maps and have a lot of activity outside of the brain. Thinking (hoping) a mask may help?
      Best,
      Natasha

      Delete
    2. Hey Natasha,

      I don't have a tutorial on how to do this in SPM, but it is usually done after preprocessing. This means that preprocessing takes more time, but it can be useful to see whether there are any systematic variations in signal outside the brain caused by hardware issues.

      The default in SPM is to create a mask during 1st-level model estimation, and to mask out any voxels that fall below a threshold relative to the global mean signal. You can create a mask manually using the Imcalc tool; e.g., the expression

      i1>100

      would mask out (i.e., set to zero) any voxels that have an intensity less than 100.


      Best,

      -Andy

      Delete
  4. Hi,

    I am new to fMRI and was wondering if I made a mask using ITK-Snap from structural images and am trying to apply it to functional data images if there is a way to get around the difference in image sizes.
    Thank you for your help!

    ReplyDelete
    Replies
    1. Hi there,

      You would need to resample the mask to be in the same space and resolution as the functional data. Look into a command like AFNI's 3dresample (e.g., 3dresample -prefix mask_RS -master funcData -inset Mask


      Best,

      -Andy

      Delete
  5. Hey Andrew,

    I'm using PRoNTo to analyze 25 .nii files of high and low grade glioma tumors.
    How much would you be able to advise me on PRoNTo?
    Thanks!
    Justin Xu

    ReplyDelete
  6. Hi, Andy

    I am interested in exporting a group summary mask (i.e., mean activation across 45 participants) to MRIcron for visualization purposes. However, the group summary mask in AFNI appears to be saved as a +tlrc file (which I believe is just text), and MRIcron requires a NIFTI file for the overlay. Would you happen to know how to visualize results from AFNI in MRIcron?

    Thanks,
    Bryant

    ReplyDelete
    Replies
    1. Hi Bryant,

      Check out the command 3dAFNItoNIFTI; for example,

      3dAFNItoNIFTI examplefunc+tlrc.HEAD

      That will create a copy that is labeled examplefunc.nii. You can change the output name by using the "prefix" option.


      Best,

      -Andy

      Delete
  7. Hi Andy,

    I have a question about the exclusive masking analysis in FSL using the command "fslmaths".

    Actually with the command "fslmaths" we can look at between two results, if a region is specifically correlated to one of these results (e.g., to show Y without X). My problem is that, however, I have three results. I wonder if we could use "fslmaths" to exclude two results from the remaining one. For example, I have three results: A, B and C. Could I use this command to show A without B, and without C at the same time?

    Thanks in advance.

    Sherry

    ReplyDelete
    Replies
    1. Hi Sherry,

      This can be done, but my method is very roundabout. Maybe you know someone younger and fitter who can think of a better way.

      1. Binarize all three maps using fslmaths -bin
      2. Multiply each by their own number (e.g., A=1, B=3, C=5)
      3. Add the maps together using fslmaths -add (any overlap between A and B will be 4, any overlap between B and C will be 8, and overlap between A and C will be 6)
      4. Threshold the resulting image so that only voxels with a value of 1 remain (i.e., only values within the A map, and nowhere else: fslmaths -uthr 1)
      5. If you want the original values, then multiply the original A map by your mask which excludes B, C, and any overlap between A and B and C.


      Hope this helps! Again, younger people are generally much better at this kind of thing than I am, so find a young person and make them do this for you.

      -Andy

      Delete
    2. Hi Andy,

      Thank you so much for your reply. It answers my question perfectly.

      Actually I have one more question. I binarized all three maps at the beginning. could I do something like this:
      1. Exclude B from A:
      fslmaths B.nii.gz -mul -1 -add 1 -mul A.nii.gz exclusive_B_from_A.nii.gz
      2. Exclude C from exclusive_B_from_A.nii.gz
      fslmaths C.nii.gz -mul -1 -add 1 -mul exclusive_B_from_A.nii.gz Only_A.nii.gz

      OR:
      1. Exclude B from A:
      fslmaths B.nii.gz -mul -1 -add 1 -mul A.nii.gz exclusive_B_from_A.nii.gz
      2. Exclude C from A:
      fslmaths C.nii.gz -mul -1 -add 1 -mul A.nii.gz exclusice_C_from_A.nii.gz
      3. Overlap these two results:
      fslmaths exclusive_B_from_A.nii.gz -mul exclusive_C_from_A.nii.gz Only_A.nii.gz

      Actually I got same results from these two ways. But I am thinking that I might miss something as I implemented the exclusive masking twice.

      I would greatly appreciate if you could have a look and advise me how to proceed.

      Thanks,
      Sherry

      Delete
    3. Hi Sherry,

      The logic of both methods is the same, so you should get the same result; I don't see why it shouldn't give you the same map as the approach I wrote out. If you look at the exclusionary map and compare it to the A.nii.gz map, does it look as though it excluded everything that was not A?

      -Andy

      Delete
    4. Hi Andrew,

      Sorry for my late reply.

      I double checked the exclusionary map. It did exclude everything that was not A.

      Thanks so much for your help.

      Sherry

      Delete
  8. Hi Andy!

    Love your blog, it's been immensely helpful! Quick question (probably quicker than you can say "Just bloody Google it"): do you know where I could find Brodmann area masks... like all of them? Juelich has a few, but there must be somewhere you can get all of them separately... right? Read that question quickly, and it's pretty quick.

    Thanks again,
    Ivan

    ReplyDelete
    Replies
    1. Hey Ivan,

      I don't think there's anyplace where you can download the Brodmann areas, but here are a couple of options:

      1. Use the wfupickatlas toolbox in SPM to save each mask separately; or

      2. Write out each Bromann area using AFNI's whereami command (e.g., for Brodmann's area 6, whereami -mask_atlas_region TT_Daemon:left:6)

      Note that each of these options is extremely tedious, which means you're doing fMRI research correctly.

      -Andy

      Delete
  9. Thanks so much Andy! Tedious is always the way to go! I ended up using pickatlas.

    ReplyDelete
  10. Hi-- I see that you posted that you went over how to create brain masks on SPM (for fMRI), but I cannot seem to find the post! If you could direct me there that would be great. Thanks!

    ReplyDelete
    Replies
    1. Hey Sarit,

      Here's a post about creating functionally-defined masks in SPM: http://andysbrainblog.blogspot.com/2014/02/saving-cluster-corrected-images-in-spm.html

      Another option is to create anatomical masks through a toolbox like wfupickatlas, which is straightforward to use. I haven't made a tutorial for that one, though.


      Best,

      -Andy

      Delete
  11. Hi Andrew,

    Congratsfor your amazing job organizing this blog. It is very helpfull!! Thanks so much.
    I am trying to perform a first level analysis using a Mask in the precentral gyrus.
    I had no problem creating the mask. However, always that I try to use this a fatal error is encountered in the post-stats:

    /usr/share/fsl/5.0/bin/fsl_sub -T 119 -l logs -N feat4_post -j 10695 /usr/share/fsl/5.0/bin/feat /home/fmri/MASK.feat/design.fsf -D /home/fmri/MASK.feat -poststats 0

    ERROR MESSAGE:
    child process exited abnormally
    END OF ERROR MESSAGE

    Do you know what I should do to fix this? I am using the FSL in a VirtualBox. I tried on different PCs, but the same error occurred.

    Thanks in advanced!!

    ReplyDelete
    Replies
    1. Hey there,

      Are you getting the error message after running it from the GUI? I haven't used fsl_sub before, so I'm not sure why it's throwing that error; it seems more likely that it's being generated by the GUI, and that something is going on at that step. Let me know some more details, and we'll see if we can figure it out.

      -Andy

      Delete
  12. Hi Andy,

    thanks for your faster answered. I am new on this, so maybe I am doing something wrong.
    I don't know why there is this "fsl_sub" there. Actually, I am using FSL 5.0.9.
    And yes, I am working in the windows 7 and 10, with a VirtualBox.

    Tks again!!
    Gabriela

    ReplyDelete
  13. sorry to ask this very basic question but tried to google it many times without any answer

    is there clear steps to get both right and left hemispheres using spm or any other tools

    ReplyDelete
  14. Hi Andy, I need to use 15 brodemann areas in my research. I'm using ADHD data from this link: http://www.nitrc.org/plugins/mwiki/index.php/neurobureau:AthenaPipeline
    This data is already preprocessed and there is a whole brain anatomical mask for each subject. I wrote out brodeman areas that I need using whereami command. Now in order to use them for ADHD data, should I resample those ROIs to anatomical mask first, and then resample it to functional data? Or should I resample them directly to the functional data? I'm also wondering is there any other step that I should do in between? I mean, is resampling the only thing that I need to do and then I can use the data?

    ReplyDelete
    Replies
    1. Hi Taban,

      In your case, you can just resample it directly to the functional data that you're extracting from. There are no steps you need to do in between.


      Best,

      -Andy

      Delete