Skip to content

Instantly share code, notes, and snippets.

Created March 22, 2013 15:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5222225 to your computer and use it in GitHub Desktop.
Save anonymous/5222225 to your computer and use it in GitHub Desktop.
##############################################################################################
##Running fsl from the command line
##some commands that I find useful
##
##############################################################################################
##############################################################################################
##############################################################################################
##Using the fslmaths and fslstats toolboxes
##############################################################################################
##############################################################################################
##To get the documentation for a the toolbox type
##############################################################################################
fslmaths
##############################################################################################
##divde two images in FSL
##############################################################################################
fslmaths 'image_1.nii.gz' -div 'image_2.nii.gz' 'output_image.nii.gz'
##you can also do things like subtract (-sub), add (-add), multiply (-mul)
##############################################################################################
##apply a mask to an image
##############################################################################################
fslmaths 'image_1.nii.gz' -mas 'mask.nii.gz' 'output_image.nii.gz'
##############################################################################################
##threshold an image to create a binary mask
##############################################################################################
##calculate the lower 15 percentile of an image, store as variable
thresh_it =`fslstats 'image_1.nii.gz' -P 15`
##threshold your image at this threshold to create a binary mask
fslmaths 'image_1.nii.gz' -thr $threshold_it -bin ../CSF_MASK/$subjscan
##############################################################################################
##calculate statistics on an image (mean, no indluding voxels with zeros) and store as variable
##############################################################################################
mean_nozeros=`fslstats 'image_1.nii.gz' -M` ##mean, not including voxels with zeros
mean_zeros=`fslstats 'image_1.nii.gz' -m` ##mean, including voxels with zeros
sd_nozeros=`fslstats 'image_1.nii.gz' -S` ##standard deviation, not including voxels with zeros
sd_zeros=`fslstats 'image_1.nii.gz' -s` ##standard deviation, including voxels with zeros
##############################################################################################
##do some calculations with these variables
##############################################################################################
fslmaths 'image_1.nii.gz' -sub $mean_nozeros -div $sd_nozeros
##############################################################################################
##create a gauss kernel of 10 mm and perform mean filtering
##############################################################################################
fslmaths 'image_1.nii.gz' -s 10 'output_image.nii.gz'
##############################################################################################
##erode a mask or image by zeroing non-zero voxels when zero voxels found in kernel
##############################################################################################
fslmaths 'mask.nii.gz' -kernel box 5x5x5 -ero 'output_image.nii.gz'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment