-
Notifications
You must be signed in to change notification settings - Fork 2
17. DTI analysis
Fa-Hsuan Lin edited this page Mar 13, 2023
·
13 revisions
Place following files in the sub-folders:
- DTI:
NOTE The above four files are used in our conventional protocol (b-value= 1,000; 60 diffusion directions)
- T1: (MPRAGE in 1-mm iso. resolution)
- T1.nii.gz (T1 images)
#!/bin/bash
# fsl runs the dcm2nii for DTI and T1 images
# output DTI.nii.gz file associated with bvecs, bvals to folder DTI
# output T1.nii.gz files to folder T1
# copy acqp,txt and index.txt to folder DTI, (need to specify source path )
dcm2niipath=./mricron
datapath=./baseball
aipath=./
filelist=$(ls ${datapath})
for ff in ${filelist}; do
echo ${datapath}/${ff};
mkdir ${datapath}/${ff}/DTI
mkdir ${datapath}/${ff}/T1
${dcm2niipath}/dcm2nii ${datapath}/${ff}/dcm_DTI
mv ${datapath}/${ff}/dcm_DTI/*.bvec ${datapath}/${ff}/DTI/bvecs
mv ${datapath}/${ff}/dcm_DTI/*.bval ${datapath}/${ff}/DTI/bvals
mv ${datapath}/${ff}/dcm_DTI/*.nii.gz ${datapath}/${ff}/DTI/dti.nii.gz
if [ -d ${datapath}/${ff}/dcm_DTI_P2A ];then
${dcm2niipath}/dcm2nii ${datapath}/${ff}/dcm_DTI_P2A
mv ${datapath}/${ff}/dcm_DTI_P2A/*.nii.gz ${datapath}/${ff}/DTI/P2A_b0.nii.gz
fi
cp ${aipath}/acqp.txt ${datapath}/${ff}/DTI/
cp ${aipath}/index.txt ${datapath}/${ff}/DTI/
${dcm2niipath}/dcm2nii ${datapath}/${ff}/dcm_T1
rm ${datapath}/${ff}/dcm_T1/o*
rm ${datapath}/${ff}/dcm_T1/co*
mv ${datapath}/${ff}/dcm_T1/*.nii.gz ${datapath}/${ff}/T1/T1.nii.gz
rm -r ${datapath}/${ff}/dcm*
done;
- Skull stripping by
bet
(default threshold = 0.5, needs tuning).
bet DTI/dti DTI/nodif_brain -f 0.5 -g 0 -m
bet T1/T1 T1/T1_brain -f 0.5 -g 0 -m
- EPI distortion correction by
topup
with non-diffusion weighted images with EPI blipped-up and blipped-down along the anterior-posterior direction.
fslroi DTI/dti.nii.gz DTI/A2P_b0 0 2
fslmerge -t DTI/A2P_P2A_b0 DTI/A2P_b0.nii.gz DTI/P2A_b0.nii.gz
topup --imain=DTI/A2P_P2A_b0 --datain=DTI/acqp.txt --subsamp=1 --config=b02b0.cnf --out=DTI/topup_results --fout=DTI/topup_field --iout=DTI/upwarp_b0
- Eddy current correction by
eddy
.
eddy_openmp --imain=DTI/dti.nii.gz --mask=DTI/nodif_brain_mask.nii.gz --bvals=DTI/bvals --bvecs=DTI/bvecs --acqp=DTI/acqp.txt --index=DTI/index.txt --topup=DTI/topup_results --out=DTI/data --ref_scan_no=0 --ol_nstd=4 --verbose
- (optional) Convert masks by
flirt
orflnrt
+convert_xfm
.
mkdir DTI/xfms
$flirt -in DTI/nodif_brain -ref T1/T1_brain.nii.gz -omat DTI/xfms/diff2str.mat -searchrx -90 90 -searchry -90 90 -searchrz -90 90 -dof 6 -cost corratio
convert_xfm -omat DTI/xfms/str2diff.mat -inverse DTI/xfms/diff2str.mat
flirt -in T1/T1_brain.nii.gz -ref $FSLDIR/data/standard/MNI152_T1_2mm_brain -omat DTI/xfms/str2standard.mat -searchrx -90 90 -searchry -90 90 -searchrz -90 90 -dof 12 -cost corratio
convert_xfm -omat DTI/xfms/standard2str.mat -inverse DTI/xfms/str2standard.mat
convert_xfm -omat DTI/xfms/diff2standard.mat -concat DTI/xfms/str2standard.mat DTI/xfms/diff2str.mat
convert_xfm -omat DTI/xfms/standard2diff.mat -inverse DTI/xfms/diff2standard.mat
- DTI metrics, such as FA and MD, by
dtifit
.
dtifit --data=DTI/data --out=DTI/dti --mask=DTI/nodif_brain_mask --bvecs=DTI/bvecs --bvals=DTI/bvals --sse --save_tensor
- Probabilistic tractography by
bedpostx
.
bedpostx DTI --nf=2 --fudge=1 --bi=1000
NOTE Sometimes the folder DTI.bedpostx
needs to be deleted and run the command again, when an error occured.
- (optional) Seed ROI for fiber tracking
!/bin/bash
# run the fsl process for DTI data
# {1} : path of case folder
# dti file in ./DTI/dti.nii.gz
# ./DTI/P2A_b0.nii.gz
# T1 file in ./T1/T1.nii.gz
# bvecs, bvals, acqp.txt, index.txt in ./DTI/
# run the bash with input of subject folder,
# for example : sh r_fsldti_nissen.sh ./sub01
fslpath=/usr/local/fsl
# bet for dti and t1 : dti, t1
${fslpath}/bin/bet ${1}/DTI/dti ${1}/DTI/nodif_brain -f 0.5 -g 0 -m
${fslpath}/bin/bet ${1}/T1/T1 ${1}/T1/T1_brain -f 0.5 -g 0 -m
# eddy with topup for dti : bvecs bvals acqp index
${fslpath}/bin/fslroi ${1}/DTI/dti.nii.gz ${1}/DTI/A2P_b0 0 2
${fslpath}/bin/fslmerge -t ${1}/DTI/A2P_P2A_b0 ${1}/DTI/A2P_b0.nii.gz ${1}/DTI/P2A_b0.nii.gz
${fslpath}/bin/topup --imain=${1}/DTI/A2P_P2A_b0 --datain=${1}/DTI/acqp.txt --subsamp=1 --config=b02b0.cnf --out=${1}/DTI/topup_results --fout=${1}/DTI/topup_field --iout=${1}/DTI/upwarp_b0
${fslpath}/bin/eddy_openmp --imain=${1}/DTI/dti.nii.gz --mask=${1}/DTI/nodif_brain_mask.nii.gz --bvals=${1}/DTI/bvals --bvecs=${1}/DTI/bvecs --acqp=${1}/DTI/acqp.txt --index=${1}/DTI/index.txt --topup=${1}/DTI/topup_results --out=${1}/DTI/data --ref_scan_no=0 --ol_nstd=4 --verbose
# registration among diff, structure(str) and standard
mkdir ${1}/DTI/xfms
${fslpath}/bin/flirt -in ${1}/DTI/nodif_brain -ref ${1}/T1/T1_brain.nii.gz -omat ${1}/DTI/xfms/diff2str.mat -searchrx -90 90 -searchry -90 90 -searchrz -90 90 -dof 6 -cost corratio
${fslpath}/bin/convert_xfm -omat ${1}/DTI/xfms/str2diff.mat -inverse ${1}/DTI/xfms/diff2str.mat
${fslpath}/bin/flirt -in ${1}/T1/T1_brain.nii.gz -ref ${fslpath}/data/standard/MNI152_T1_2mm_brain -omat ${1}/DTI/xfms/str2standard.mat -searchrx -90 90 -searchry -90 90 -searchrz -90 90 -dof 12 -cost corratio
${fslpath}/bin/convert_xfm -omat ${1}/DTI/xfms/standard2str.mat -inverse ${1}/DTI/xfms/str2standard.mat
${fslpath}/bin/convert_xfm -omat ${1}/DTI/xfms/diff2standard.mat -concat ${1}/DTI/xfms/str2standard.mat ${1}/DTI/xfms/diff2str.mat
${fslpath}/bin/convert_xfm -omat ${1}/DTI/xfms/standard2diff.mat -inverse ${1}/DTI/xfms/diff2standard.mat
# dtifit for typical diff parameters such as MD, FA: bvecs bvals
${fslpath}/fsl/bin/dtifit --data=${1}/DTI/data --out=${1}/DTI/dti --mask=${1}/DTI/nodif_brain_mask --bvecs=${1}/DTI/bvecs --bvals=${1}/DTI/bvals --sse --save_tensor
# bedpost for probabilistic diffusion model
${fslpath}/bin/bedpostx ${1}/DTI --nf=2 --fudge=1 --bi=1000
close all; clear all;
targ=MRIread('/Users/fhlin_admin/workspace/seeg/subjects/s057/mri/orig.mgz');
subject='s057';
targ_reg=eye(4);
dti=MRIread('DTI/dti_FA.nii.gz');
% do registration between pre- and post-OP by the following command:
%
% cd /Users/fhlin_admin/workspace/seeg/subjects/s057/tmp
% bbregister --s s057 --mov ../../../s057/DTI/nodif_brain.nii.gz --init-coreg --reg register.dat --t2
%
% %check registration
% tkregisterfv --mov ../../../s057/DTI/nodif_brain.nii.gz --reg register.dat --surfs
dti_reg=etc_read_xfm('file_xfm','/Users/fhlin_admin/workspace/seeg/subjects/s057/tmp/register.dat'); %for MAC/Linux
dtim=MRIvol2vol(dti,targ,dti_reg);
etc_render_fsbrain('surf','orig','hemi','rh','subject',subject,'vol',targ,'overlay_vol',dtim,'overlay_threshold',[0.3 0.5]);
return;