Monday, November 19, 2012

Creating Masks In FSL

Due to a high number of requests (three), I have made some walkthroughs about how to create masks in FSL. There are a few different ways to do this:

  1. Anatomical ROI: These masks are generated from anatomical regions labeled by atlases. For example, you may decide to focus only on voxels within the V1 area of visual cortex. Using an atlas will create a mask of that region, based on the atlas-defined anatomical boundaries in a standardized space.
  2. Functional ROI (or contrast ROI): This is a mask created from a contrast thresholded at a specific statistic value. For example, you may wish to focus only on voxels that pass cluster correction for the contrast of left button presses minus right button presses.
  3. Painting ROIs: This is where the real fun starts; instead of being confined by the limitations of anatomical or contrast boundaries, let your imagination run wild and simply paint where you want to do an ROI analysis. Similar to what you did in first grade, but more high-tech and with less puking after eating your crayons. (Is it my fault that Razzmatazz Red sounds so delicious?)
Demonstrations of each approach can be found in the following videos:

 Anatomical ROIs

Functional ROIs

 ROIs created from FSLview. Pretend like you're Bob Ross.

89 comments:

  1. Thanks Andy for another great post. I have a picky question...how do you determine the threshold value (10 in this case)?

    ReplyDelete
    Replies
    1. Hi Amy,

      Are you referring to the thershold for a specific contrast? That is somewhat arbitrary, as you may decide to use a very stringent threshold for further analyses, or something more liberal. Really, you're just saying something along the lines of "I've made this z-value the threshold for determining whether a cluster is significant, and I will only use those cluster(s) for further ROI analyses."

      Hope that helps!

      -Andy

      Delete
    2. Thanks Andy. That's sort of what I thought. Amy

      Delete
  2. Thanks! This is really helpful. I have a question. I am trying to create the mask of ROI and use it on the actual human brain images to analyze the stiffness of the specific region in the brain. Since you used the standard brain image in FSL, I am not sure how I can match the mask generated from the standard brain image to the actual brain image scanned by MRI. Or, is there another way to do that?

    Thank you.

    ReplyDelete
    Replies
    1. Hi Sangmin,

      What do you mean by "stiffness"? I haven't come across that term before.

      In any case, you can create ROIs for individual subjects using the same procedure as outlined above, just for each subject's brain. However, it also depends on whether you want to do it before or after normalization, which can introduce large spatial interpolations and warps into each participant's anatomical image. If you want to create an ROI before normalization, just be aware that you won't be able to use the standard atlas for defining anatomical ROIs; you will have to do those by hand (and most people recommend having an experienced neuroanatomist do it for you).


      Best,

      -Andy

      Delete
    2. I am working on a study to measure elasticity of the brain in healthy people, using a new MRI technique called Magnetic Resonance Elastography (MRE). If I want to use the standard atlas to create ROIs for each subject's brain, you are saying that I should normalize the image at first, right? However, I am not so sure how to normalize the MRI images. Do you also have the tutorial for this?

      Thank you,

      Sangmin

      Delete
    3. Hi Sangmin,

      Yes, that is correct; to use atlases in a standardized space, you would need to normalize your functional image first. There is a brief discussion of normalization, along with a video, at the following link: http://andysbrainblog.blogspot.com/2012/11/spm-setting-origin-and-normalization.html


      Best,

      -Andy

      Delete
    4. Hi Andy,

      I followed the steps to normalize my functional image. When I checked the image registration, it matched the template image pretty well. However, the dimension of the normalized image does not match to the one of the standard image, so I can't apply the atlas to the normalized image to create the mask from it. Is there also any way that I can match their dimensions?

      Thank you.

      Delete
    5. Hey Sangmin,

      They should have the same dimensions if they are normalized; I would double-check to make sure that you are using the correct functional images, since they may be in a different folder. If not, you can use flirt to apply the transformation matrix that is output after warping your anatomical to a reference image, e.g.:

      flirt -in func_001.nii.gz -ref $FSLDIR/data/standard/MNI152_T1_2mm \
      -out func_001_norm -applyxfm -init ../reg/example_func2standard.mat

      Hope this helps,

      -Andy

      Delete
    6. Hi,

      Thank you for the reply. I actually used FLIRT linear registration (FSL) and it worked well! I have a question about the atlas. Do you know if there is an atlas for corpus callosum of the brain? I am interested in this region, but could not find the atlas for it :(

      Thanks!

      -Sangmin

      Delete
    7. Hi Sangmin,

      Unfortunately, I don't know of any atlases that include the corpus callosum; the only option I can think of is to try and paint it in yourself, or have a trained anatomist do it, and then export it as a mask.

      -Andy

      Delete
  3. Hi Andy,

    It's my first time using fsl and your videos really helped me.
    I just wonder if there is any easy way to "select" a once painted mask and move it around.
    I'm making ROIs of peripheral nerves, having multiple sequences of the same region. The thing is that the sequences don't overlap perfectly and i have to make a new ROI every time (it's about a 1-4 voxel shift in mostly one direction). It would be a lot easier if i could take the mask of one sequence and adjust it to the others instead of having to redo them every time.

    Thanks in advance!
    Alex

    ReplyDelete
    Replies
    1. Hey Alex,

      Just letting you know, I haven't forgotten about this; I'll get around to it soon. If I don't respond by Friday, ping me again.


      Best,

      -Andy

      Delete
    2. Hey Alex,

      Sorry for the late response; I was looking into it, and unfortunately there is no elegant way to do what you want with FSL. The closest thing I can think of would be AFNI's 3drotate tool, which allows you to translate and rotate 3D images slightly; but even this would take a lot of time, since you would have to check your output after each transformation. I don't know of any software packages that store the images in memory and allow you to manipulate them by clicking and dragging ROIs until they match up.


      Best,

      -Andy

      Delete
    3. Thank you very much Andy!
      I already tought as much, but it's good to here it from someone experienced. I'll definitely have a look at the 3drotate tool, it might still be less time consuming than making new ROIs for every sequence.

      Kind regards,
      Alex

      Delete
  4. Hi Andy,

    Thanks for these useful videos. I am just starting to use FSL for some DTI analysis. I would need to create an exclusion mask, i.e., one whole hemisphere. Is there an easy way of creating one of those with FSL? Also, I created some anatomical masks of the frontal cortex based on the Havard-Oxford atlas in FSL but these are also bilateral. How can I split them into left and right ROIs separately?

    Any help would be appreciated.
    Best wishes,
    Conny

    ReplyDelete
    Replies
    1. Hi Conny,

      You could create a hemisphere mask by using the whole brain as a mask, and then creating another mask where all voxels to the right (or left) of the midline are 1's. Then, you would use fslmaths to do a logical AND of both masks to create a single mask for only one hemisphere. A similar approach could be used for splitting your frontal cortex mask.

      -Andy

      Delete
    2. Hi Andy, great vids, I have a question that follows up on your answer to Conny here. Is there a simple way using FSL tools to create a mask where all voxels to the right (or left) of the midline are 1's? Thanks,
      Michael

      Delete
    3. Hey Michael,

      What you could do is use fslmaths to both binarize the mask, and take one hemisphere. Note that this will depend on how many voxels there are in the x-direction (which I think is dim1 if you do fslhd on the image), but you will need to divide that number in half. For example, if there are 91 voxels in the x-direction, the halfway point should be roughly 45 voxels.

      You could then use a command like the following:

      fslmaths inputImage.nii -bin -roi 45 -1 -1 -1 -1 -1 -1 -1 outputImage.nii

      Where the -1's represent covering the full extent in the x-, y-, and z-directions.


      Hope this helps!

      -Andy

      Delete
    4. Hi Andy,

      I am wondering how you can get the number of voxels in one direction (in this example, 91 voxels in the x direction). Thanks a lot.

      Thank you,
      Tima

      Delete
    5. Hey Tima,

      You can use fslhd, which will give you voxels in the x-, y-, and z-dimensions (represented by dim1, dim2, and dim3). If you just wanted the number of voxels in the x-direction, you could do something like:

      fslhd file.nii | grep dim1

      -Andy

      Delete
    6. Hi Andy,

      Thanks for all this helpful information! I'm wondering if there is a way to use this approach but for a specific plane rather than for hemispheres. For example, if you have a structural mask and want to exclude everything posterior to y = 10?

      Thank you,
      Kristin

      Delete
  5. Hi Andy,

    Great blog! I have an FSL beginner questions: If I have a few white matter masks (creating using FSL atlases), how do I put them in the same space as my FA, MD, etc maps (from dtifit) to pull mean FA, MD, etc. from those areas?

    Also, do you have any recommendations for pulling whole brain FA? Would I create a white matter mask using FAST?

    Any help you can provide would be much appreciated! Thank you!!
    Cristina

    ReplyDelete
    Replies
    1. Hi CFR,

      I am getting started on a series of tutorials for DTI, so let me get back to you on that in a little bit (probably by next week). I apologize for the delay, but I want to be sure about it before giving you an answer!

      -Andy

      Delete
  6. Hi Andy,

    In you "Creating Anatomical ROIs" video, you note that you should threshold and binarize the ROI mask you create in FSLview. Might you be able to explain why it's important to do this? Should one binarize all anatomical ROIs (e.g., let's say you want to pull FA values from DTI data, should you binarize the mask you make?)?

    Thank you!
    Cristina

    ReplyDelete
    Replies
    1. Hi Cristina,

      Actually, you can do it either way; if you do not binarize the mask, it will weight your parameter estimates by the probability of the voxel being included in the mask. If you do binarize the mask, then all parameter estimates will be extracted from that ROI "as is", without any weighting.

      Either approach is fine; however, I'm more familiar with multiplying every voxel value within the mask by 1, and excluding everything else outside of the mask. You can do whatever approach works best for you.

      Thanks for bringing this up, though - I probably should have clarified that in the video. Making the mask binary isn't necessarily the "correct" way to do it.

      Best,

      -Andy

      Delete
  7. Hi Andy- great blog! I'm just wondering whether there is 'standard' threshold to be used when creating ROIs from atlases. You have used 10 in your example, but I imagine something like 50 be too conservative? Is there a value that 'most' people use?

    ReplyDelete
    Replies
    1. Hey, thanks! As far as I know, there is no 'standard' threshold; most of the atlases are probabilistic, so really it's up to you to determine how much of it you want to retain. If you have no threshold at all, you'll probably get all of the structure, but possibly some other areas as well. As long as you're clear about what you're including, I think you should be OK.

      -Andy

      Delete
    2. Thanks Andy- your blog is really helpful!

      Delete
  8. Hi Andy,
    Thank you for making these tutorials--they are so incredibly helpful!

    Could I ask your advice on the most efficient way to create a mask with several distinct ROIs from a functional map with several distinct clusters?

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. Hi Andy,

    Thank you so much for this blog! So helpful!

    Could I ask about using this binary mask to extract an ROI for subjects who have also been converted to standard space?
    For instance, I have completed a FSLVBM and I would like to extract the significant voxels and look at the grey matter concentrations using fslstats for the ROI that changed. So I would like to extract an ROI of only significant voxels. I can create a binary mask but do not know how to progress.

    Thank you so much,
    Maz

    ReplyDelete
  11. Hi Andy,
    Thank you for this blog.
    I am quite lost in comparing of two segmentations. For comparing of two segmentations it is generally used Modified Hausdorff Distance but it works with surfaces and I have only binary maps of two different segmentations. I think that surface mask is binary mask with value 1 only in surfaces voxels and the interiors voxels are 0 like the background. Is it true? Is it possible to create surface mask based on binary mask and use the surface mask for Hausdorff Distance analysis? I prefer FSL but if you recommend me any other software for solution this task I will be glad.
    Thank you,
    Marek

    ReplyDelete
  12. Thank you for your blog, it's incredibly useful! By chance, do you know why when bizarized ROIs in standard space (e.g., MNI) are transformed to subject space, you do not end up with a binarized ROI in subject space? In FSL view, the intensity values range from .00001 to .99999 in subject space (vs. 0 or in MNI space). It seems that in order to binarize in subject space, the fslmaths command must be performed after the transformation has occurred.

    Any insight into this process? I'm wondering that if you do not binarize in subject space as well, if it's best to use a "weighted mean" option when extracting an ROI time series?

    ReplyDelete
    Replies
    1. HI EDub,

      That is usually because the ROIs are interpolated when they are transformed to subject space. You can either do the binarizing (binarization?) after the transformation, or do a transformation with no interpolation, such as nearest neighbor. For example, with FLIRT, try the -interp option with "nearestneighbour".


      Best,

      -Andy

      Delete
  13. Hi Andy,

    Thanks so much! Very helpful.

    Is it problematic if the the ROIs were not binarized (or did not have the "no interpolation" option specified) following transformation to subject space? I ran my 1st Level PPI models leaving the ROIs "as is" (interpolated), but I can certainly re-run. I'm not sure if (or how) this would affect interpretation of the data.

    Thank you again!
    --Erin

    ReplyDelete
    Replies
    1. Hi Erin,

      I don't know if it's problematic; I would try redoing the analysis with just one subject and see if the results change very much. If not, you should be fine with your analysis as it is. My guess is that your results won't be significantly affected.

      -Andy

      Delete
  14. Wonderful, thank you again, Andy. I did a test and binarized one ROI in subject space, then extracted the time series using fslmeants. The time series was identical to the one generated from the interpolated ROI. Thus, it seems my results should not be affected with either method.

    Many thanks!
    --Erin

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  16. Hi Andy,
    Once you create an mask in fsl using an atlas, can this mask be used as an ROI in other programs? I'm hoping to use a fsl atlas to define an ROI and then use that ROI to run resting state analyses with SPM and marsbar. I've been having trouble opening the mask in marsbar and have tried multiple file types.

    Hoping you can help!
    Thanks,
    A fellow Carleton Alum

    ReplyDelete
    Replies
    1. Dear Schiller,

      NIFTI format would be your best bet, as I've been able to use it with Marsbar in the past. (Also, make sure that you unzip it using gunzip if it's output in gz format.) Are you using the most current version of Marsbar? What kind of error is it giving you what you try to open it?

      -Andy

      Delete
    2. I hadn't been unzipping the .gz files. Now that I did that, it worked fine in Marsbar! Thanks so much!

      -Anne

      Delete
  17. Hi Andy,
    Thanks for video
    I created a mask from Atlas.
    And I want it with a probability threshold of 5%
    I used command like below
    fslmaths mask.nii.gz -thrp 5 -bin mask_thr.nii.gz
    Am I right?
    thanks

    ReplyDelete
    Replies
    1. That's correct! You can check it out for yourself by taking a mask, such as the paracingulate gyrus, thresholding it at 5%, and then comparing that to the mask you create with fslmaths. They should be the same.

      -Andy

      Delete
  18. Hi andy, thanks for the videos they've been really helpful.

    I have 3 diferent ROIS, each one is a .nii file, already binarized. But i want to make a mask including this 3 ROIS each one with 1, 2 and 3 value respectively. What do you suggest?
    Thank you again.

    ReplyDelete
    Replies
    1. Hi Ana,

      If you're using fslmaths, you can use the -mul option on each mask separately: e.g.

      fslmaths mask1.nii -mul 1 mask_1.nii
      fslmaths mask2.nii -mul 2 mask_2.nii
      fslmaths mask3.nii -mul 3 mask_3.nii

      You can then add them all together:

      fslmaths mask_1.nii -add mask_2.nii -add mask_3.nii mask_1_2_3.nii

      Note that any overlap will be the sum of the value of those masks; for example, overlap between masks 1 and 3 would be 4, and overlap between masks 2 and 3 would be 5.

      Best,

      -Andy

      Delete
  19. Hi, is there a way to establish the size of the voxels in the mask?. Because for example I have data dimensions of 64x64x38 and I need an atlases to visualize it. Thank you Andy

    ReplyDelete
    Replies
    1. Hey Melanni,

      Just use a header tool, like fslhd, to determine the size of the voxels. For example, typing

      fslhd YourNIFTIfile.nii | grep pixdim

      will return the dimensions in the x-, y-, and z-directions (pixdim1, pixdim2, and pixdim3).

      -Andy

      Delete
  20. Hi Andy,

    ​many thanks for the​ great and helpful tutorials. I am new in fMRI analysis, So, my question might be so simple. I use HCP data for my research. I have an issue about parcellation functional fMRI images with AAL 116 atlas and I do not know what should I do, because I do not have the AAL atlas in functional space, I tried to make it by transforming structural AAL atlas from structural space to functional space, but I did not get a good result. Maybe I am doing something wrong. By the way, transforming the atlas to functional space was the only way that I thought it would work but it did not. I would appreciate it if you could guide me how to do the parcellation of the functional image with AAL 116 atlas in FSL? or suggest me some gentle references on this.
    Many thanks in advance.

    Best,
    Narges

    ReplyDelete
    Replies
    1. Hello Narges,

      I haven't used the AAL atlas, but I'm assuming it's in some kind of standardized space - such as MNI space. Is there a particular reason why you want to transform the AAL atlas to functional space? Why not warp the functional images to standard space, and then do the parcellation there?

      In any case, you will need to first transform the functional images to standardized space. That will generate a transformation matrix standard2highres.mat, and you can use the inverse to transform the AAL atlas to the subject's native space with a command like this:

      flirt -in AAL_atlas.nii -ref func_data.nii -applyxfm -init
      standard2highres.mat -datatype float

      Best,

      -Andy

      Delete
    2. Hi Andy,

      Thanks for your reply. I did the transformation to standard space (both atlas and functional image) but there is an issue here, because before transformation the atlas just has integer values but after transformation to standard space, it contains decimal values too. I added "-datatype integer" in transformation command but I am concerned that I would miss some data with this command.
      For example, after transformation, I have a voxel with the value of 12.52. So, how can I decide that this voxel is a part of the region with value 12 in this or region with the value of 13?
      Generally, can I transform the atlas to the standard space without having decimal values?
      I just wanted to compare my functional image to structural image via their atlases. I am wondering whether does the transforming both to standard space would be correct for comparing them or not?
      I would appreciate it if you could help me, and thanks again for your great tutorials and your time.

      Narges

      Delete
    3. Try "-interp nearestneighbour", which assigns the closest value to the new voxel, instead of introducing any interpolation.

      -Andy

      Delete
    4. thank you very much for your reply, I really appreciate that.
      I have now another problem. When I transform the functional image(4D) to the standard space it turns to a 3D matrix and I miss the timeseries. Do you have any suggestion to fix this issue?

      Narges

      Delete
    5. Hi Narges,

      Normalization has two stages: Warping a representative image to standardized space (usually the anatomical image, which has already been coregistered to your functional images), and then applying that transformation - stored in highres2standard.mat - to all of your functional images.

      Assuming you already have the highres2standard.mat file, do the following to apply that transformation matrix to your functional images, and bring them to standardized space:

      flirt -in func.nii -ref template.nii -out func_warped.nii -init highres2standard.mat -applyxfm

      Make sure the functional image is a concatenated NIFTI file with all of the functional images for that run. You can check this with fslhd.


      Best,

      -Andy

      Delete
    6. Hi Andy,
      Thank you for your reply. Do you mean applying "functional2standard.mat" transform? Because I want to transfer my functional image to standard space. So I think we should use "functional2standard.mat" instead of "highres2standard.mat", and as I mentioned in my previous comment when I apply "functional2standard.mat" I miss 4th dimension of the functional image.
      Many thanks for your help.

      Best,
      Narges

      Delete
    7. Hey Narges,

      Yes, in that case use functional2standard.mat. It's been a while since I've used FSL, so I can't remember what exactly gets output.

      It's difficult to debug why this isn't being applied to all of your functional runs. Have you tried it through the GUI?

      -Andy

      Delete
  21. Hey Andrew,
    Is it possible to extract FA and MD values of a subject from each roi ?

    ReplyDelete
    Replies
    1. Hi,

      You should be able to extract those using featquery, or any other ROI tool from the other software packages, using the FA or MD maps as an input.

      -Andy

      Delete
    2. Can you please suggest me any roi tools other than marsbar and featquery? Basically, I want to extract these values without running any group analysis.

      Delete
    3. Yes, you can use AFNI's 3dmaskave (which only requires a mask and an input, which can be in NIFTI format). You can also use the SPM command spm_get_data, which I outline here: http://andysbrainblog.blogspot.com/2014/07/quick-and-efficient-roi-analysis-using.html

      -Andy

      Delete
  22. Hi Andy,

    Thanks for making some awesome tutorials, they've really helped me understand a lot. I am a master's student working on my thesis. I'm completely out of my league looking at fMRI scans for concussion analysis as I've never used FSL or done anything with any MRI before. I'm currently trying to assess FA and MD maps of individuals with specific regions of interest I've selected from a DTI scan. My advisor (who also has no background in this) and I have been wondering why no universal masks for roi's have been created, and if they have, where are they?

    Thanks,
    Sophia

    ReplyDelete
    Replies
    1. Hi Sophia,

      Good to hear from you! Actually there are atlases for white matter tracts, such as the JHU atlas in FSL. Take a look at one of these videos and let me know if that's what you need: https://www.youtube.com/watch?v=Ds-kmqovC7U

      -Andy

      Delete
  23. Hi Andy,

    Once I have created the mask is there any way to permanently combine it with a T1 image so that it becomes one nifti file? They are the same dimensions and overlay fine in fslview. I have tried adding the files using fslmaths but the resulting image does not show the mask at all.

    Thanks
    Zoe

    ReplyDelete
    Replies
    1. Hi Zoe,

      What do you mean exactly by "combining" the T1 and the mask? If you mean that you want them to be in the same file, you can use a command like fslmerge to combine the two; e.g., fslmerge -t T1_mask_combined.nii T1.nii mask.nii

      This example would create a 4D dataset, with the T1 image as the first volume and the mask as the second volume.


      Best,

      -Andy

      Delete
    2. Hi Andy,

      By "combining" I mean that rather than loading the T1 image in fslview and then adding the mask file to be able to see it on top of the T1, I want to be able to make it one file so that I can view one nifti file and it will be the T1 image with the mask on it. The reason for doing this is in ExploreDTI I can only add one .nii file, I need to view the tracts on top of both the T1 and the mask but cannot do this if they are separate files. I tried the fslmerge command but it just showed the T1 image, the same as when I used fslmaths.

      Thanks

      Zoe

      Delete
  24. Hi Andy, thanks for the awesome videos! This may be a ridiculous question but I have a ROI mask that is not in MNI space, that I want to use to analyze my data. Is there a way to bring this into MNI space? I don't know what structural was used to register it but it's a whole brain mask with multiple ROIs so I'm wondering if I can somehow move it to MNI space?
    Thanks,
    Isha

    ReplyDelete
    Replies
    1. Update: it seems like the mask in in Talairach and I'd like to convert it to MNI coordinates. I have the ROI area names as well as the Talairach z coordinates. Would you know of a way to accomplish this?
      Many thanks,
      Isha

      Delete
    2. Hi Isha,

      The easiest way to do that would be to use AFNI's 3dWarp tool, and use the following syntax:

      3dWarp -tta2mni yourdataset.nii -prefix yourdataset_mni.nii


      Best,

      -Andy

      Delete
    3. Thanks Andy! We actually ended up creating our own mask using fsleyes and an atlas as you'd wonderfully described in one of your videos.
      Best,
      Isha

      Delete
  25. Hi Andy,

    Great website. I have always found your tutorials very helpful!

    For a project I need to create a mask in fsl, based on Atlas Tools data, that has dimensions of 80 x 80 x 30 with a voxel resolution of 3x3x4, to match that of functional data I have.

    When I create the mask using the method you describe, I get volume dimensions of 182 x 218 x 182 and a voxel resolution of 1x1x1mm (when using a 1x1x1 standard image). I have figured out how to adjust the voxel size using fslchpixdim, but I'm not sure how to change the volume dimensions. Any suggestions?

    Thanks!

    Brandon

    ReplyDelete
    Replies
    1. Hey Brandon,

      Thanks! I try to keep things humming around here.

      To resample one image to another in FSL, I use flirt; e.g.,

      flirt -in mask.nii.gz -ref data.nii.gz -out mask_rs.nii.gz

      Where mask.nii.gz is the mask you created from Atlas Tools, and data.nii.gz is your functional data. Check the output dataset (mask_rs.nii.gz) using fslhd, and make sure that the dimensions and resolution match up.

      Best,

      -Andy

      Delete
    2. Thanks Andy,

      I didn't realize functional data could be used as a reference image.

      Brandon

      Delete
  26. Hi Andy,
    Thanks for maintaining this website and for your responses! Quick question, is there a way to move a binary mask by a known amount in the x, y or z direction(s)? For example, if I want to move the entire mask up by 3 pixels?

    ReplyDelete
    Replies
    1. Hey there,

      The best tool for that would be AFNI's 3drotate command; e.g.,

      3drotate -prefix ROI_Rotated.nii -ashift 0 3 0 ROI.nii

      This would shift your ROI by 3mm in the y-direction. The arguments after the -ashift option represent the amount to shift the image in the x-, y-, and z-directions.


      Best,

      -Andy

      Delete
  27. Sreekrishna Ramakrishna PillaiJanuary 26, 2018 at 6:17 PM

    Hi Andy,
    You had previously replied to one of the comments above on how to transform the AAL atlases to subject space using the the inverse transformation matrix using FSL. Is it possible do the same with SPM?
    I am trying to do this for ROI analysis of Cerebral Blood Flow (CBF) maps. I coregistered the subject's T1 weighted image to the CBF Map. Then used 'Normalize:Estimate' step to get deformation field matrix that can be used to transform T1 image to MNI space.
    Is there a way to use the inverse of this deformation field to transform the AAL ROIs (which seems to be in MNI space) to the subject's CBF space?

    ReplyDelete
  28. Hi Andy,
    I was wondering whether I could create a mask choosing a range of intensity values from FSLview. We are working on T1 mapping and want to create a mask for voxels with T1 intensities between 900-1100. So basically, create a mask using lower and upper threshold as 900 and 1100.

    Thanks,
    Chaitali

    ReplyDelete
  29. Hi Andy,

    These tutorials are so helpful!! I did have a question. Would you be able to explain the difference between -thrp and -thrP? I'm running the code: fslmaths name.nii.gz -thrP 5 name_thresh, which i understand. But why does -thrp give me different results?

    ReplyDelete
  30. Hi Andy, is there any way to save the centroid of a mask as a different image in FSL? It is my understanding that you get the coordinates of the centroid of a mask using the fslstats command with the -c or -C option but is there any way to pipe this output to create a mask with a different name (essentially a single pixel mask)? Thanks!

    ReplyDelete
  31. Hi Andy,

    Thank you so much for this blog. It is very useful.
    I need your help in my analysis.
    I have created ROIs from SPM fMRI analysis, which is in nii format.

    Using Freesurfer I want to calculate the cortical volume, thickness, area and curvature of these masks.

    I ran the recon-all for all the subjects.
    I know how to calculate these measures using DK atlas. But when I have a mask from SPM based fMRI analyses, I don't know how to extract it.

    Could you please share your thoughts on this problem.

    Thank you.

    ReplyDelete
  32. Hi Andy,
    How are you?
    Can you suggest me how to perform simple threshold method to create mask on BraTS18 Brain MRI(.nii format) data?
    There are four types of information for a patient such a flair, t1, t1ce and t2.

    ReplyDelete
  33. Hi!

    I have a mask for a very small ROI (25 voxels) at 2mm. I would like to change resolution to 3mm. I used:

    flirt -in 2mm_mask.nii.gz -ref 2mm_mask.nii.gz -init fsl/etc/flirtsch/ident.mat -applyisoxfm 3.0 -interp nearestneighbour -o 3mm_mask.nii.gz

    This command worked well for my other (larger) ROIs, but for this one, the resulting 3mm ROI is only 2 voxels. Of course, I expect it to shrink, but not by that magnitude.

    Is the nearestneighbour interpolation the cause? I am able to get something more logical by simply using trilinear interpolation and the thresholding and binarizing the result. However, I would like to determine the cause - I think it's small ROI + nearestneighbour method?

    Thanks for the helpful blog!


    ReplyDelete
  34. Hi Andy,
    thank you very much for the video.
    I was wondering if you have ever tried to register a multiregion mask to a template (like MNI space). I have tried to use FLIRT to do that (actually I registered the T1 to the MNI space and then applied the same transformation to the mask). What happens is that the values of my pre and post registration mask are not the same. Let's say I have a 15 for the insula, in the registered mask I still have 15 in the insula but I have some random 15dots a bit all over the place.
    Do you know how I can avoid this?
    Thank you very very much!

    ReplyDelete
  35. Hi Andy,
    I was hoping you could help me. I'm using FSLview and math to create different masks based on the Havard-oxford atlases. However, many of them are bilateral, and in some cases I only need the unilateral mask. Do you have an easy way of doing thís? THe only example I found did not work for me, but since I have found great help in your youtube tutorials I thought you might be able to help me on this matter as well. Looking forward to hearing from you.
    Kind regards, Line

    ReplyDelete
  36. I was reading your article and wondered if you had considered creating an ebook on this subject. Your writing would sell it fast. You have a lot of writing talent. face masks

    ReplyDelete
  37. Hi Andrew,
    I saw that you suggested using a whole head mask, which I assume includes the extracranial soft tissues (orbits, etc). Do you have any recommendations for how to generate that, perhaps using bet? I attempted to use fslmaths -bin but there are voxels containing signal outside the brain (and setting a -thr invariably removes some desired tissue within the head). Thanks!

    ReplyDelete
    Replies
    1. Hi there,

      You could try a more robust brain extraction tool such as optiBET (https://montilab.psych.ucla.edu/fmri-wiki/optibet/), or you could use AFNI's 3dSkullStrip tool with the -avoid_eyes option. The most sophisticated way to generate a brain mask would be with fMRIPREP, which takes a long time, but generates a high-quality mask: https://andysbrainbook.readthedocs.io/en/latest/OpenScience/OS/fMRIPrep_Demo.html

      -Andy

      Delete
  38. Hi,

    Andy, Would you please tell me how to smooth the edges of the mask? Right now, the edges are really coarse.

    Many Thanks,
    Suren

    ReplyDelete