#!/bin/sh
# Use nonlinear registration tools
# to register from native space to standard space.
# 1) First run FSL linear registration (flirt).
# to produce an affine transform matrix (*.mat)
# of the T1w image to MNI space.
flirt -ref MNI152_T1_1mm_brain -in T1w_brain -omat affine_transform.mat
# 2) Run fnirt to create the warp field (--cout=nonlinear_transform)
# by passing in the linear transform. This is slow (~15 minutes).
# The nonlinear transform is a NIfTI image containing a gradient.
fnirt --in=T1w --aff=affine_transform.mat
--cout=nonlinear_transform --config=T1_2_MNI152_2mm
# 3) Once we have the warp field, it is quick to apply it to the
# T1w image to create the T1w image in MNI space:
applywarp --ref=MNI152_T1_1mm --in=T1w
--warp=nonlinear_transform --out=T1w_MNI
#---------------------------------------------------
# applywarp: apply a warp file to another image
# convertwarp: combine a warp file and a mat file to generate a new warp file
# invwarp: swap the warping direction
#---------------------------------------------------
# applywarp example: warp the MNI space image into the B0 dti space
# This example requires an existing warp image created by fnirt
applywarp -r img_B0 -i img_mni --out=img_mni2B0 --warp=mni_b0
# warp the 4D functional image into MNI space
# The reference is the MNI image (-r MNI_stand)
# The input is the native space fMRI image (-i fMRI_4d)
# The output is the fMRI image warped into the MNI space (--out=fMRI_4d_mni)
# The warp image must already exist (--warp=fMRI_mni)
applywarp -r MNI_stand -i fMRI_4d --out=fMRI_4d_mni --warp=fMRI_mni
#-----------------------------------------------------
# convertwarp: create a warp image (-o run_mni) from an existing warp
# image (-w str_mni) and a mat file (-m run_str). Use a reference
# (-r stand) equivalent to the one used to generate the warp.
convertwarp -r stand -w str_mni -m run_str.mat -o run_mni
#-----------------------------------------------------
# invwarp: invert the run_mni warp file to create the new
# mni_run warp file. -r is the new reference file name
# (determines output FOV and pixdims)
invwarp -w run_mni -o mni_run -r sub-001_run1_basevolreg
#!/bin/sh
# Some viewers (like MRIcron) do not handle anisotropic voxels well.
# FSL can easily convert an image with anisotropic voxels into one
# with isotropic voxels in the same space using -applyisoxfm
# reslice current image into 1mm isotropic
flirt -in anat_CT_axial -ref anat_CT_axial -applyisoxfm 1 -out anat_CT_axial_1mm
# reslice current image into 0.5 mm isotropic voxels.
flirt -in anat_CT_axial -ref anat_CT_axial -applyisoxfm 0.5 -out anat_CT_axial_0.5mm
#!/bin/sh
# Use FSL flirt to register label masks
# with nearest neighbor interpolation.
# because the label values should never be interpolated.
# This example assumes:
# an existing 0.5mm standard brain (MNI152_T1_0.5mm_brain)
# an existing flirt matrix from 1 mm to 0.5 mm (stand1stand0.5.mat)
flirt -in atlas -datatype int -ref MNI152_T1_0.5mm_brain
-interp nearestneighbour
-init stand1stand0.5.mat -applyxfm -out atlas_0.5mm