User Tools

Site Tools


Sidebar

Quick Navigation:

Home

EEG/ERP

MRI

fMRI

DTI


Blog

dti_in_afni

In Progress…

Motion Correct & Co-Register

The first step is to correct for movement and coregister to the anatomical volume. This is partially equivalent to eddy correction in FSL as well as registration, fortunately in AFNI this is accomplished in one step. For ease of processing, first copy your high-res anatomical and DWI file to AFNI format using 3dcopy. Then use align_epi_anat.py to accomplish the motion correction and registration.

3dcopy Sag3dMPRage.nii.gz anat3d
3dcopy ep2ddiff32dirs007a1001.nii.gz dti
align_epi_anat.py -anat anat3d+orig. -epi dti+orig. \
-epi_base 0 \
-suffix _al2dti \
-cost mi \
-giant_move \
-epi_strip 3dAutomask \
-epi2anat \
-tshift off -volreg_method 3dAllineate

The align_epi_anat.py options define the high-res, the DWI image, uses a mutual info cost function, sets the image base for the DWI image, tells the script to align the DWI image to the anatomy (instead of the other way around), and “AddEdge” will output a folder by the same name that shows the overlay of the co-registration similar to FSL and the Haskins Viewer (bisregister). This will output a file called dti_al+orig, indicating that it is aligned.

Compute Diffusion Tensors in Subject Space

3dDWItoDT -prefix tensors.nii.gz \
-automask -reweight -verbose 100 \
-eigs afni.bvecs.txt dti_al+orig

The options prefix specify the output file, automask automatically only computes within the brain (you could specify your own mask if you wanted), reweight is the other part of eddy correction to reduce the weight for voxels in gradients that have more noise at the voxel's location, verbose tells the program to output every 100 voxels, this option can be excluded I just like to see the program do things, eigs computes eigenvalues, eigenvectors, fractional anisotropy and mean diffusivity and places them into sub-briks 6-19 (the same as running 3dDTeig).

The bvecs file needs to be in a “3-column” format. Note that it was necessary to delete the row of zeros in the first line to work with AFNI. I usually manipulate these files using Excel to transpose and then export as tab-delimited text.

0.12655893 0.983086646 0.132376119
0.159535304 0.305615395 -0.938694715
-0.658078611 -0.743210375 0.120709859
0.428845763 -0.279818594 -0.858948708
0.015464032 0.712138951 0.701868236
-0.015459481 -0.712567925 -0.701432824
0.88024348 -0.253771812 -0.400962889
0.371462703 -0.894551933 0.248580545
-0.614687383 -0.613994598 -0.495146513
-0.42018193 0.504160643 -0.754499316
-0.855804324 0.482302517 -0.187038034
0.976849854 0.211827084 0.029893948
-0.370504379 0.895417213 -0.246889725
-0.271377623 -0.176322028 -0.946184278
0.658096075 0.743344247 -0.119787112
-0.516725481 0.779214203 0.354711175
0.420828223 -0.504318357 0.754033566
0.713946342 0.337519497 -0.613482833
0.271018535 0.176473767 0.946258903
-0.429668188 0.279679298 0.858582973
0.516354024 -0.779650331 -0.354293495
-0.792576075 -0.007095173 -0.609731793
0.615091503 0.613099456 0.495753527
-0.713946342 -0.337519497 0.613482833
-0.976909637 -0.211746812 -0.028474938
-0.159535304 -0.305615395 0.938694715
0.855776906 -0.481925517 0.188132226
0.792358935 0.007404382 0.610010266
-0.186633319 -0.814600646 0.54917556
-0.88024348 0.253771812 0.400962889
-0.126691073 -0.983196437 -0.131431133
0.18638511 0.815422237 -0.548039377

Make Color Maps for Display

These two steps make the Red, Green, Blue color maps for display and publications. One note is that the STEP(c-0.25) will threshold FA values of at least .25.

3dcalc -prefix DTIout \
-a 'tensors.nii.gz[9..11]' \
-c 'tensors.nii.gz[18]' \
-expr 'c*STEP(c-0.25)*255*ABS(a)'

3dThreetoRGB -prefix DTIColorMap \
-anat 'DTIout+orig.[0]' 'DTIout+orig.[1]' 'DTIout+orig.[2]'

If you happened to have separate datasets (like from FSL) your code would look like this:

3dcalc -prefix DTIout \
-a DTI_V1+orig \
-c DTI_FA+orig \
-expr 'c*STEP(c-0.25)*255*ABS(a)'

3dThreetoRGB -prefix DTIColorMap \
-anat 'DTIout+orig.[0]' 'DTIout+orig.[1]' 'DTIout+orig.[2]'
dti_in_afni.txt · Last modified: 2014/10/16 12:03 by pmolfese