fsl nonlinear registration code example

Example: fsl nonlinear registration

#!/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

Tags:

Misc Example