Saturday, April 27, 2013

FSL Tutorial: Creating ROIs from Coordinates

Previously we covered how to create regions of interest (ROIs) using both functional contrasts and anatomical landmarks; however, FSL can also create spheres around voxel coordinates, similar to AFNI's 3dcalc or SPM's marsbar.

  1. Step one is to find the corresponding voxel coordinates for your MNI coordinates, which may be based on peak voxel activation from another study, for example; to do this, open up FSLview, type in your MNI coordinates, and write down the corresponding voxel coordinates (these are shown in the bottom-left corner of FSLview). 
  2. After you have written down your voxel coordinates, create a point at those coordinates using the fslmaths command. This command requires the template space that you warped to, as well as the actual x-, y-, and z-coordinates corresponding to the MNI coordinates. Give the output file a name, and make sure that the output data type ('odt') is set to float. (Example command: fslmaths avg152T1.nii.gz -mul 0 -add 1 -roi 45 1 74 1 51 1 0 1 ACCpoint -odt float)
  3. Using fslmaths again, input the file containing the point created in the previous step, and specify a sphere of radius N (in millimeters) to expand around that point. Use the -fmean command, for reasons that are to remain mysterious, and provide a label for your output data set. (Example command: fslmaths ACCpoint -kernel sphere 5 -fmean ACCsphere -odt float)
  4. Update on 5/18/2016: To make it a binary mask, execute one more command: fslmaths ACCsphere.nii.gz -bin ACCsphere_bin.nii.gz. The previous step creates a sphere, but with small intensities; this can be problematic if you do a featquery analysis that allows weighting of the image.

Once that is all done, use fslview to open up a template in your normalized space, and overlay your newly created sphere; double-check to make sure that it is in roughly the location where you think it should be. Now you can extract data such as parameter estimates from this ROI, using techniques similar to those covered in previous tutorials about ROIs.

Thanks to alert viewer danieldickstein, which, due to its juvenile reference to the male member, cannot possibly be his real name. Grow up, Daniel.


87 comments:

  1. Your blog is a great resource! OK, I know how to create spheres around a particular coordinate already, but what if I want to create a mask that includes multiple such spheres - let's say, a "mentalizing mask" that includes areas in the mPFC, PCC and TPJ, for example? How would I do that in fsl so I could then extract info from featquery? Thanks!

    ReplyDelete
    Replies
    1. Hi,

      You can combine masks using a command like:

      fslmaths -add -add -add

      When you use featquery on the resulting output, though, it is an average over all of the masks that you have added together; you will not be able to distinguish which extraction came from which mask. The way around this would be to run Featquery_gui on each mask individually, then use the output code in a script to loop over subjects.


      Thanks for the question!

      -Andy

      Delete
  2. Hi Andy, how would one go about creating a square ROI? I want to create a square ROI to match our ROI in Spectroscopy data from the Anterior cingulate. This will then be used as a seed for resting state analysis in MELODIC. Many thanks in advance.

    ReplyDelete
    Replies
    1. Hello,

      You can create an ROI using a command similar to the one listed above (i.e., -kernel sphere 5), but just replace "sphere" with "box" (e.g., -kernel box 5). You can also create rectangles of unequal length, width, and height using a command like -kernel boxv xx.

      See the help output from fslmaths for more information.


      Hope this helps!

      -Andy

      Delete
  3. Hi Andy, great advice thanks. When I try to create a ROI with a radius larger than 10 mm I get some very strange output..any ideas how to create a ROI of radius e.g. 12?

    Best,
    Anders

    ReplyDelete
    Replies
    1. Hi Anders,

      I wasn't aware of that issue until now, but you're right - it looks strange! I'm not sure how to get around this issue using fslmaths, although there are a couple of alternatives you could try:

      1. Manually fill in the voxels around a sphere of 10mm until you get the desired ROI size that you want (which will be pretty tedious); or

      2. Try creating the ROI in another program, e.g. AFNI or SPM's Marsbar toolbox, and then convert it to nifti format to be read by FSL.

      I haven't seen anything about creating an ROI greater than 10mm using fslmaths, so unfortunately I'm at a loss for how to do that through FSL.


      Best,

      -Andy

      Delete
    2. Here's the fsl thread regarding this issue - with thresholding instructions that allow for the creation of a clean roi > 10 mm

      https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=ind1008&L=FSL&P=R53884&1=FSL&9=A&J=on&d=No+Match%3BMatch%3BMatches&z=4

      Delete
    3. Thanks, Natalie! That's very helpful.

      Delete
    4. more easier way is :
      add another fslmaths and set -thr XXXX(just look your sphere intensity)-bin
      like
      fslmaths ACCsphere -thr 0.001 -bin ACCsphere_mask

      Delete
  4. Hi, Andy, do ou know how to use the coordinates generated to process a group, do I have to manually input the coordinates of each subject? Anything like a for loop can be used?
    Thanks,

    ReplyDelete
    Replies
    1. Hi Wen,

      For a group-level analysis, usually it is better to create a mask at the group level; in other words, if you have warped everybody's data to a common space, such as MNI, then I would create the coordinates in MNI space and extract your parameter estimates from there. The procedure for creating an ROI in group space should be similar to creating ROIs in an individual's space; just be aware of the Left/Right conventions, and always double-check that the ROI you created matches up with where you think it should be.


      Best,

      -Andy

      Delete
    2. Thanks for the quick reply.
      I am trying to create spheres of all subjects around the peak value within a mask, I 've got the coordinates for each subject, just don't know how to loop it so that I don't have to input manually.
      Any suggestions?

      Delete
    3. Hi Wen,

      If you have a list of coordinates, then you could put it in a for loop using tcsh. For example, you could set up a for loop with your subjects, and then have a conditional to set the x, y, and z-coordinates. Something like the following:

      for subject = (101 102)
      if $subject == 101 then
      x = 30
      y = 40
      z = 50
      elseif $subject == 102 then
      x = 32
      y = 37
      z = 51
      end if

      fslmaths avg152T1.nii.gz -mul 0 -add 1 -roi {$x} 1 {$y} 1 {$z} 1 0 1 ROI_{$subj} -odt float

      end

      This is just pseudocode, but you get the idea. It might be easier to use something like Python or a language that can read in a datafile, but this should work. Play around with it and let me know if you have any questions.


      Best,

      -Andy

      Delete
  5. Hi Andrew,

    First of all, thanks for your blog!

    I'm trying to extract ROI (made from your video-tutorial) time-course using fslmeants function (fslmeants -i filtered_func.nii.gz -o my_timecourse.txt -m your_roi_mask.nii.gz), but FSl said: "ERROR: Mask and Input volumes have different (x,y,z) size."

    ROI size:
    dim1 91
    dim2 109
    dim3 91
    dim4 1
    pixdim1 2.0000000000
    pixdim2 2.0000000000
    pixdim3 2.0000000000
    pixdim4 0.0000000000

    Functional image size:
    dim1 80
    dim2 80
    dim3 40
    dim4 240
    pixdim1 3.0000000000
    pixdim2 3.0000000000
    pixdim3 3.4500000477
    pixdim4 1.0000000000

    I supose that it's due to pixdim value, but probably the easiest way to solve that is increasing ROI pixdim value to 3.

    Any suggestion?

    Thanks again!

    Roger

    ReplyDelete
    Replies
    1. Hi Roger,

      It looks as though the functional image has not been warped to a template space yet; you are still dealing with the original voxel dimensions, instead of an image that has been resampled to 2x2x2 (which is the FSL default for most of its templates). Try redoing it with your processed functional images.

      -Andy

      Delete
  6. Hi Andrew

    We have the same issue as Roger and I wondered if you found a solution to resolve it?

    Thanks a lot
    Marion

    ReplyDelete
    Replies
    1. Hi Marion,

      I just posted a reply to Roger's question; basically, it seems as though the functional image he was dealing with had not been resampled to the template space of 2x2x2 dimensions for each voxel.

      -Andy

      Delete
  7. Hi Andy- Thanks so much for your excellent tutorials! I just used this one and now I'd like to run an ROI analysis in FSL. In the past, you discussed doing an ROI analysis in featquery, but it seems to me that I could save time by using fslmeants on my group analysis.
    It seems like I should be able to go into the appropriate cope directory in my group analysis and run fslmeants with my input as the filtered_func_data, and my ROI mask. The output should be the PE for each subject for that mask and contrast, yes? So I could then take this list of PEs and run a one-sample t test to see if it is significantly greater than zero. If so, I have a significant difference for my contrast in that ROI. Does that make sense or am I missing something totally obvious?
    (Apologies if this posts twice, I'm having some Internet issues!)

    ReplyDelete
    Replies
    1. Hi Lauren,

      I haven't done it that way in FSL, but that seems like a perfectly good approach; I don't see any problems with it. I've done a similar method with SPM using the command spm_get_data, which is like doing the command line version of Marsbar, which is a little different.

      I would test that out on a simple contrast and also run featquery on the same thing to see if you get similar results. They may not be identical due to some differences in ROI definition or extraction with featquery, but they should be pretty close. I'd be interested to know how that goes!

      -Andy

      Delete
  8. Hi Andy,

    Do you have suggestions for how to create an ELLIPTICAL roi around two points? I have looked around and there is surprisingly little.

    Thanks,
    Malathi

    ReplyDelete
    Replies
    1. Hey Malathi,

      I haven't thought about that, although I could see how it would be useful. There may be a way to do this with AFNI's 3dcalc (check the command help), by messing around with the foci of the coordinates. However, I'm not sure. Good question though!

      -Andy

      Delete
  9. Hi Andy,

    I'm trying to create spherical ROIs from long list of coordinates (>100 regions) which I have in .csv file. Can you tell me how to create this ROIs in fast way? I'm quite new in FSL.

    Best,
    Caroline

    ReplyDelete
    Replies
    1. Hi Caroline,

      I'm sure there's something I could figure out, but it would take some time to code. If you want, email me at ajahn@indiana.edu and we can work out some of the details.

      Best,

      -Andy

      Delete
  10. This comment has been removed by the author.

    ReplyDelete
  11. Great blog, very useful. For my purposes (a binary ones and zeros mask), I adapted the code above to use -dilM instead of -fmean and dropped the float. Hopefully this is helpful to someone else.

    ex (using a spherical ROI in the pons):

    fslmaths IMAGE.NII -mul 0 -add 1 -roi 79 1 75 1 22 1 0 1 PONSpoint
    fslmaths PONSpoint -kernel sphere 7 -dilM PONSsphere7

    ReplyDelete
    Replies
    1. Hey, thanks! Besides not crashing when specifying large kernel sizes (which is awesome), are there any other advantages to the dilM option?

      Best,

      -Andy

      Delete
  12. Good question, I'm not sure really. I just used it to avoid the binarize step. For various reasons (some shamefully asthetic) I wanted a ones and zeros mask and that is what it gives you.

    ReplyDelete
  13. Hi Andew,
    Thank you very much for you blog!!
    Now what I have is a excel file which save 264 ROIs' coordinates in MNI space.
    What I want to do is create one mask which has all of the 264 ROI on it.
    Is there any way the FSL can read the excel file directly or I need to type into all the coordinates by using -add in fslmaths option?
    Thank you very much!!

    ReplyDelete
    Replies
    1. Hey Junhan,

      I don't know of any way that FSL can directly read in an Excel file to create ROIs (although my knowledge is limited), so you may need to use the -add option.


      Best,

      -Andy

      Delete
  14. Hi Andy,
    thanks a lot for your tutorials-great, clear and better than Nutella:).
    I have a question regarding ROI. I have created ROI using your comments above, overlaid it on MNI152_T1_1mm. Looks great-what i wanted. But after that i have the problems:
    1. As far as i know, FSL does not resample functional, it registers it to standard via structural (subject's). And this is possibly why i cannot overlay the ROI on a subject's functional - it complains that there are different dimensions in anatomical and my EPI.
    2. My ROi is created in standard space using voxel coordinates. How i can convert my ROI into MNI (which does not use the voxel coordinates)? For example, when i used my preprocessed (and normalised to MNI152_T!_1mm) EPI and my mask (created as in your tutorial above using a coordinates from previous study), it appears that my ROI is in a completely wrong place!
    Am i am doing something completely stupid?
    Would really appreciate your comments, as it will save my mental health:))
    thanks a lot
    alla

    ReplyDelete
    Replies
    1. If you register your functional image to the anatomical image, it should fix that. You can use FSL's FLIRT command, although it is not as good of a registration as some other methods.

      Delete
  15. Hi Andy,

    Your tutorials are great! I had a question regarding the code you used. When I used the fslmaths command, I got the following error:

    fslmaths avg152T1.nii.gz -mul 0 -add 1 -roi 65 1 71 1 50 1 0 1 Point1 -odt float
    Error: failed to open file Point1.nii.gz
    ERROR: Could not open image Point1
    Image Exception : #23 :: Failed to open volume Point1 for writing
    terminate called after throwing an instance of 'RBD_COMMON::BaseException'
    Aborted (core dumped)

    Do you know what I did wrong? And how I can fix this issue? Thank you!

    ReplyDelete
    Replies
    1. It doesn't look like an error with your code. It might be that you do not have permission to write a file in the directory that you are currently in?

      Delete
  16. You should really add one more command line to make the mask binary.
    fslmaths ROI_Left -bin ROI_Left_bin

    The fslmaths command to use it as a mask '-k' doesn't work because it means everything, so you have a really small intensity on the mask. Making it binary solves this issue!

    ReplyDelete
    Replies
    1. Good catch! I believe that featquery automatically binarises the mask, but in case it doesn't, I've updated the commands to include the binarise option.

      -Andy

      Delete
  17. hi Andrew,

    When I used your following fslmaths avg152T1.nii.gz -mul 0 -add 1 -roi 45 1 74 1 51 1 0 1 ACCpoint -odt float

    this message shows up: Cannot open volume avg152T1 for reading!

    any idea want the problem might be?

    thanks!

    ReplyDelete
    Replies
    1. ok, I figured it out. just had to copy paste the exact mane of the MNI image...

      Delete
    2. Hey there,

      I just got to this question, but I'm glad you figured it out! I've been there more times than I can count.


      Keep it hot,

      -Andy

      Delete
    3. Hi Andrew,

      This blog and your videos have been extremely helpful to me. Just to follow up about the previous question on this thread, I have also been getting the "Cannot open volume" error and have not been able to resolve the problem. I have modified permissions to be rwx on all of the standard template files, and also copied and pasted the exact name of the MNI image (avg152T1.nii.gz) and am still receiving the error. It does not work for the handful of MNI template files I have tried.

      Code:

      fslmaths avg152T1.nii.gz -mul 0 -add 1 -roi 64 1 83 1 47 1 0 1 Krmpotichpoint -odt float
      Cannot open volume avg152T1 for reading!

      Do you have any suggestions?

      Thank you,

      Kelly

      Delete
    4. Hey Kelly,

      Is avg152T1.nii.gz in the directory where you are running the command? Try that.

      -Andy

      Delete
    5. Thanks for your response, I was running it out of the same directory. A colleague helped me realize that I needed to create the .fslconf directory in my home folder, which mysteriously didn't exist despite the fact that I've been using FSL for over a year on this computer - and we didn't create a single file within it; the directory identity just needed to be created. I was able to do the rest following your tutorial!

      Delete
  18. Hi Andrew, thanks for this! I was just curious- for creating a sphere in MNI template (2mm template) if you choose a 9mm sphere, is it 9mm radius and 18 mm diameter? Or 9mm diameter? And if it is a 9mm diameter, and 2mm space, does it split the voxels at the edge "in half", so for example it is 4 and 1/2 voxel radius?

    ReplyDelete
    Replies
    1. Hi there,

      The number refers to the radius of the sphere, not the diameter. For example, a 5mm sphere would have a 10mm diameter.

      The mask will always cover whole voxels (never half a voxel or a fraction of a voxel), and the placement of the sphere affects which voxels become part of the mask. For example, if you are in a space with 2mm isotropic voxels and you place a 5mm sphere at the coordinates <0 0 0>, then the mask would cover from -4 to +4 in each direction. Different software packages may differ in how they round up or down to the nearest voxel.


      Best,

      -Andy

      Delete
  19. Hi Andy,

    Any idea how I might make a mask that cuts off after a given coordinate in one dimension and extends to the edge of the volume in the other two, for example if I wanted only the top half of the brain?

    Best,

    Emily

    ReplyDelete
    Replies
    1. Hi Emily,

      I don't know how to do that in FSL, but you could do something like this in AFNI:

      3dcalc -a anat_template -expr 'ispositive(z-0)' -prefix hemisphere_z.nii

      That would give you a mask of everything above the z coordinate of 0; you could then multiply that by a whole brain mask to only get voxels within the brain dorsal to a z of 0.

      See this message board post for more details: https://afni.nimh.nih.gov/afni/community/board/read.php?1,49827,49828#msg-49828


      Best,

      -Andy

      Delete
  20. Hello Andrew,
    Your tutorials are fantastic. Thanks!
    I have just performed TBSS analysis, and found significant difference in 5 areas (clusters). Now, I would like to extract the FA values in those 5 ROIs, Hence, I am creating spherical ROIs using fslmaths, so I can extract the FA values. Is this approach correct? Do you have any idea how to extract FA values particularly for my 5 ROIs?
    I have followed your instructions, but failed to create the ROI mask based on the voxel coordinates, and therefore I was not able to extract FA values for my 5 clusters/ROIs.
    Hope you will help me.
    Thanks in advance.

    ReplyDelete
    Replies
    1. Hi Anonymous,

      I realize this is late but if anyone else is wondering, it depends on whether you want to value within the whole region that was significant by TBSS or just the peaks.

      If you want the whole region, just treshold the statistical image from randomise at your desired significance level (e.g. 0.95) and then binarize it to form the template.

      If you just want the FA value at the peaks of the clusters, follow this tutorial using the cluster peaks from cluster or autoaq as the ROI coords.

      Delete
  21. Hi Andy,

    I have my mask and I'm trying to use my group level (gfeat) directories with Featquery. However, when I try and use a subjects gfeat directory, the stats selection part of the gui goes blank. I am however able to use any of the cope.feat folders within the overall gfeat. Are you aware of any issues in doing this?

    Cheers,
    D

    ReplyDelete
    Replies
    1. Hi D,

      If you want the group-level stats, then you need to select the FEAT directories within the gFEAT directory. For example, if you had 5 contrasts at the single-subject level and ran group-level tests on all of those, you should have 5 cope directories within your gFEAT directory. Try using featquery on those directories.

      Best,

      -Andy

      Delete
  22. Hi Andy,
    I was wondering if you know a way to split an anatomical mask into its constituent voxels. Something like the kernel argument of fslmaths? But the ROI is not a box, its anatomical region. Thanks for all the useful resources!

    ReplyDelete
    Replies
    1. Do you want each voxel as an individual mask? If so, I'm not sure how to go about that.

      -Andy

      Delete
    2. Yes, I was hoping for each voxel as a mask. Ok, no worries, thanks for getting back to me!

      Delete
  23. Hi Andy!

    Thanks for your videos! Always learn from them.

    I'm wondering if we can use FSL or Afni to extract time series signals from Harvard-Oxford atlas? I know that FSL has this atlas in it. But it seems we can just create the ROI from the coordinate one by one. As for afni, it doesn't have HO atlas in it. So we only have to use 3dcal to get those signals by inputting coordinate?

    Thanks!

    ReplyDelete
    Replies
    1. Hi Tracy,

      Yes, you can create the mask with FSL and then extract data from it using AFNI's 3dmaskave. However, you need to make sure that both the mask and the dataset you are extracting from have the same resolution and voxel dimensions, which you can convert using 3dresample.

      First, create the mask with FSL as in the video, and then resample it to your dataset (or, conversely, resample your data to the mask; but it's better to make as few alterations to the data as possible):

      3dresample -master data.nii -input HO_mask.nii.gz -prefix HO_resampled.nii

      3dmaskave -quiet -mask HO_resampled data.nii


      Best,

      -Andy

      Delete
    2. Hi Andy,

      Thanks for your quick reply. I just realized one thing that I may not fully understand.

      So we can use FSL to create atlas related masks. And in your video we use the standard template T1 image to get those masks. My question is, with our own data, when creating masks for group analysis, what kind of images should we get the masks from? The standard T1 image as in the video, the subject's own T1 image, or the template we use when doing alignment in preprocessing?

      In my case, I preprocessed all subjects' data in Afni and warpped anatomy to standard space MNI_avg152T1. The output voxel resolution is 2.5mm. (Seems all templates in FSL don't match? they are 2, 1 or 0.5mm...)

      The question seems a little bit silly. But anyway I just found I used 3dcalc and fMRI data not the T1 image to create masks before. Is it wrong?

      -Tracy

      Delete
  24. Hi Andy,

    As I'm not interested in between subjects analyses, I did not do any registration at all (I didn't warp to any template space). I'm using a localiser run to get my peak activation x,y,z coordinate, and want to create a sphere around this to test my experimental conditions against. Without having warped to any space during initial analyses, what would you suggest I use for this command? fslmaths avg152T1.nii.gz -mul 0 -add 1 -roi 45 1 71 1 51 1 0 1 ACCpoint -odt float. My localiser and experimental runs are in the space space (we kept the coverage the same).

    ReplyDelete
    Replies
    1. P.S. For this line..'fslmaths avg152T1.nii.gz -mul 0 -add 1 -roi 45 1 71 1 51 1 0 1 ACCpoint -odt float' I replaced the template image with a zstat image, is this doable?

      On a seperate note, despite that I'm creating a 5mm sphere, it is only appearing as 1 voxel when I check it with FSLview. Any ideas why this is?

      Delete
    2. Hi David,

      Yes, you can use a zstat image instead of the template image; the image you select will determine the boundaries of the ROI image and its voxel resolution.

      Did you do this step to create the sphere? fslmaths ACCpoint -kernel sphere 5 -fmean ACCsphere -odt float

      Note that if your voxel resolution is quite large, e.g. around 5mm isotropic, then you will need to specify a greater sphere size to incorporate additional voxels into the mask outside of the initial point you created.

      In reply to your first question, I would use FSL's cluster command to determine the peak coordinates of your activation, noting the voxel coordinates in FSL view, and then using those coordinates with the fslmaths commands.


      Best,

      -Andy

      Delete
  25. Andy,

    Thanks a ton for your detailed tutorials. I'm trying to create a spherical ROI of specified radius around a specified point in the MNI space. The command fslmaths point_mask_1.nii.gz -kernel sphere 5 -fmean -bin sphere_mask_1.nii.gz seems to work but as soon as I increase the radius to 6(mm) instead of 5, the output blows up and creates random patches over the entire ROI. Any thoughts? Thank you!

    ReplyDelete
    Replies
    1. Hey there,

      There used to be a workaround for this, but I lost the link to it; another approach is to create the ROI through FSLeyes (which is included with the most recent FSL update: https://youtu.be/Vaj7BBxqXt0?t=202)


      Best,

      -Andy

      Delete
  26. Hi Andrew,

    First of all: thank you for you blog!

    Here is my question:

    I have download an ROI mask from Neurovault but when I try to add this mask to my standard image in FSL view, I have the following message: “unable to load compatible overlay”. Then I tried with fsleyes and it worked.

    However, when I try to run group analyses with this mask it gaves me errors…. (the analyses work fine and when using a sphere mask that I build based on your video, that is by using FSL MNI space).

    Any idea of what I should do?

    Thank you for your help!

    -Damien

    ReplyDelete
    Replies
    1. In the meantime, I've downloaded another mask from Neurovault and builded using fsl. This mask work when used in my group analyses.

      Thus, it seems mask created with SPM (or other) does not fit in FSL. How could I fix this problem?

      Thank you!

      Delete
    2. Hi Damien,

      This is probably because the dimensions of your mask and the data you're trying to extract from are different; for example, your data might have a resolution of 2x2x2, while the mask has a resolution of 1x1x1. You would need to either resample the mask to the data, or resample the data to the mask. I recommend resampling the mask to the data, so that you don't add any more interpolations to the data.

      FSLview would throw an error if you tried to open two images that didn't have the same dimensions; although that was annoying, it did tell you if the images had different grids. FSLeyes doesn't throw that error anymore, which is less annoying, but it also doesn't let you know if the images have different grids.

      You can check the image dimensions with fslhd and compare the pixdim 1-3 fields. If they are different, you can resample one image to another like this:

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


      Best,

      -Andy

      Delete
    3. Thank you so much for your fast answer. What does data.nii.gz refers to?

      When I tried with the MNI space, the mask_rs and the MNI space have the same size! (I used the following line: -in mask.nii.gz -ref MNI152_T1_2mm_brain_mask.nii.gz -out mask_rs.nii.gz)

      Thank you!

      Delete
    4. OK, I think I found the solution based on https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FLIRT/FAQ

      flirt -in mask.nii.gz -ref MNI152_T1_2mm_brain_mask.nii.gz -applyxfm -usesqform -out mask_rs.nii.gz

      Thanks again!

      Delete
  27. Hi Andy,

    I have a problem with a MRS mask. For MRS, I used a 2/2/2 cm3 VOI placed in DLPFC. For fMRI-MRS correlation study, I created a ROI using MarsBar. The native space( at subject level) coordinates where obtained from the dicom header info.
    For instance, for one subject had x, y, z = (-30.609 56.386 55.924).
    Andy, Is there a way to get the MNI or Tal x, y, z information from the subject level x,y,z info?

    Any suggestions would be greatly appreciated.

    ReplyDelete
    Replies
    1. Hey Anupa,

      Was the MRS image warped to MNI space? Or are you trying to warp the ROI (created in MNI space) to the subject's native space? If the latter, use SPM's "Reslice" tool to convert the standardized ROI to native space. Otherwise, it is not possible to get MNI coordinates from an image that hasn't been warped yet.

      Best,

      -Andy

      Delete
  28. Hi Andy,
    No, the image was not warped to MNI space.
    The MRS voxel was placed in the subjects' brain and the coordinate information were read from individual MRS raw data header in Matlab.

    Now, one of the reviewer asked me on the possibility of information of x,y,z coordinates in std stereotaxic space?
    I have no idea on ho to transform it to the std space.
    Any thoughts!!!?

    ReplyDelete
    Replies
    1. Hey Anupa,

      Unfortunately, you need to warp the image to standardized space before you can determine what the coordinates are.

      -Andy

      Delete
  29. I've run probtrackx on several hundred subjects (subcortical seed to 5 targets). I have the waytotals. I've split my subjects into 2 groups based on some variable (high vs. low responders). What's the best way to compare potential differences in connectivity between my seed and the targets for these 2 groups? Do I normalize fdt_paths by way total and average across subjects then do an ANOVA? Or do I normalize the seeds_to_target files and average those.

    -A

    ReplyDelete
  30. Hi Andy,

    I'm trying to extract ROI time-course using fslmeants function (fslmeants -i filtered_func.nii.gz -o my_timecourse.txt -m your_roi_mask.nii.gz). I have no problem extracting one ROI time course but having trouble extracting multiple ROIs' time courses. Could you please help me with this problem? Thank you!

    ReplyDelete
    Replies
    1. Hi Claire,

      Try giving it the --label option, and make sure that each part of the mask has a different number associated with it. For example, let's say you have a mask file composed of two distinct regions: The DLPFC and the ACC. The DLPFC should have values of 1 for each voxel in that mask, and the ACC should have values of 2 for each voxel in its mask.


      Best,

      -Andy

      Delete
  31. Hi Andy,

    Thanks for all your great work! I have some task data and I'm trying to extract the mean time series from an ROI mask (coordinates defined in a relevant meta-analysis) that I've then transformed into individual subject space in FSL. I'm struggling however with what the appropriate input files would be for the fslmeants command, and from which level of analysis (i.e., first-level, second-level, or third-level) I should extract the time series from once I have my mask transformed into each subject's functional space. Any thoughts you had on this question or my general approach would be greatly appreciated, thank you!

    Best,
    Steven

    ReplyDelete
    Replies
    1. Hi Steven,

      I would extract them from the second-level results (e.g., those beta weights that have been averaged over the runs for the subject). I think that these values are also output at the third-level group analysis level as well.

      -Andy

      Delete
  32. Hi Andy,

    Thanks for the useful tutorial. It works perfectly when I used the coordinates mentioned in this tutorial. However, when I use my own MNI coordinates [0 -52 7], it saves the output file but when I overlay this on the template, it doesn't show anything. I ran following commands:

    fslmaths avg152T1.nii.gz -roi 0 1 -52 1 7 1 0 1 PCCpoint -odt float
    fslmaths PCCpoint -kernel sphere 6 -fmean PCCsphere -odt float
    fslmaths PCCsphere.nii.gz -bin PCCsphere_bin.nii.gz

    I would really appreciate any help.

    Best,
    Sahil

    ReplyDelete
    Replies
    1. Hi Sahil,

      Did you also include the -mul 0 and -add 1 options?

      -Andy

      Delete
    2. Dear Andrew,

      I had the same problem. Save the sphere and when I overlay nothing can be seen... Someone that solved this issue? ps. I included -mul 0 and -add 1 options

      Delete
  33. Hello,its very helpful. However when i was doing like this with coordinate of vmPFC, the results is just black screen with nothing when loaded in FSLeyes.

    ReplyDelete
    Replies
    1. You should see it; have you looked through all the slices in all directions?

      Delete
  34. Hi Andy,
    Thank you for the videos! I have a total newb question and I'm hoping you can help. I think I've installed FSL correctly on my mac OS X yosemite. If I launch fsl from my (bash) terminal, I can get to fslview from the gui and then "file>open standard" to view avg152T1.nii.gz
    However when I try to use the fslmaths command to read this file I get this error: "Cannot open volume avg152T1 for reading!"
    This is my code:

    bash-3.2$ mkdir my_fsl_vbm avg152T1.nii.gz
    mkdir: my_fsl_vbm: File exists
    bash-3.2$ fslmaths avg152T1.nii.gz -mul 0 -add 1 -roi 45 1 74 1 51 1 0 1 ACCpoint -odt float
    ** ERROR (nifti_image_read): short header read 'avg152T1.nii.gz'
    ** ERROR: nifti_image_open(avg152T1): bad header info
    ERROR: failed to open file avg152T1
    Cannot open volume avg152T1 for reading!


    Any clues on how to fix this? For now I'm just trying to plot a bunch of dots on the brain at once.

    ReplyDelete
  35. Hi Andy,

    I'm trying to use your code, but I cannot see the roi_point I created. I also double checked with fslstats -R. The third hint that something is going wrong is that the sphere_roi creation gets stuck and never happens (I guess because the input file is just zero).
    My input coordinates are in voxels space, but I also tried MNI space. I must be doing something wrong.

    Any suggestion?

    Here is my code:
    fslmaths $TOPDIR/$T1 -mul 0 -add 1 -roi ${MNI_x[i_roi]} 1 ${MNI_y[i_roi]} 1 ${MNI_z[i_roi]} 1 0 1 $TOPDIR/roi_point_temp.nii.gz -odt float
    fslmaths $TOPDIR/roi_point_temp.nii.gz -kernel sphere 5 -fmean $TOPDIR/roi_sphere_temp.nii.gz -odt float

    Thanks,
    Ilaria

    ReplyDelete
  36. Thanks a lot for this blog!

    ReplyDelete
  37. Hi Andrew -

    Thanks for this blog. I have a question. I am comparing Non smokers > smokers in the CONN toolbox and I have significant differences in the ROI - ROI connectivity values between the Salience Network and the FP network. The coupling shows as RED (positive). Does this mean that smokers have greater coupling in this network than non smokers?

    Thanks,

    Jake.

    ReplyDelete
  38. Hi Andrew,

    Upon creating several mask using the harvard-oxford atlas, i was wondering if the thresholding would be according to the index of each different subcortical area? or would it be '0.5', just a 50% threshold?

    After binarising, if I would like to bind the different masks together, should I relabel them but using the fslmaths mul, where i multiply all of them by a different number, and then add them up so I can identify the different rois in my analysis?

    After binarising and I would like to reference them to subject space. However I do not have a transformation matrix as i used fmri prep to pre process my data. I created one transforming the mask to subject space using fslflirt, however it doesn't map well on fsleyes. Do you have any idea what I should do?

    thank you so much,

    Dione

    ReplyDelete
    Replies
    1. Hi Dione,

      The probabilities of the masks in fsleyes are on a scale from 1-100, so if you wanted to threshold a mask in include only those voxels with a 50% chance or above, you would use something like:

      fslmaths mask.nii.gz -thr 50 mask_thr50.nii.gz

      And yes, you can use fslmath's "-mul" option to label each mask. When you add them together, be aware that any masks that overlap will be the sum of the individual masks that overlap.

      Regarding your last question, I'm not sure how to do that, aside from the steps I've outlined here: https://tinyurl.com/yau4svou

      Best,

      -Andy

      Delete
  39. Hello everyone,

    I fixed the "Mask and Input volumes have different (x,y,z) size" error with resizing my Schaefer atlas to the size of my images (zALFFMaps) using SPM ImCalc.
    Now the problem is that the result of the "fslmeants" command contains just two integer (instead of 400, because I'm using the Schaefer2018_400parcels atlas):

    >fslmeants -i allZstats_resized.nii -m Schaefer2018_400Parcels_17Networks_order_FSLMNI152_2mm.nii
    results: 0.003911
    -0.040982

    Do you have any idea what my problem might be?

    ReplyDelete