fsl reg

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


3.6
5
Jo Mercer 70 points

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

3.6 (5 Votes)
0
3.5
8

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

3.5 (8 Votes)
0
4
10
Yoshi810 80 points

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

4 (10 Votes)
0
4
6

                                    #!/bin/sh

: <<COMMENTBLOCK

Purpose:    Run flirt to reslice an image into a new space
Input:     	img = image to be resliced, 
            ref = a reference image (we will reslice INTO this new space)
            -init mat = a mat (matrix) file that expresses the relationship between 
            the input space and the output space
Output:     -out = image in new space

COMMENTBLOCK

    flirt -in img -datatype float -ref ${ref} -init ${mat} \
    -applyxfm -out ${output}

4 (6 Votes)
0
4.29
7
Brad Graham 115 points

                                    #!/bin/sh

: <<COMMENTBLOCK

Purpose:    Run flirt to reslice an image into a new space
Input:     	img = image to be resliced, 
            ref = a reference image (we will reslice INTO this new space)
            -init mat = a mat (matrix) file that expresses the relationship between 
            the input space and the output space
Output:     -out = image in new space

COMMENTBLOCK

    flirt -in img -datatype float -ref ${ref} -init ${mat} \
    -applyxfm -out ${output}

4.29 (7 Votes)
0
4.5
2

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

4.5 (2 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source