I think its best to run eddy current correction first and then apply the B0 map correction. I have included here a bash script which shows how to process the B0map and the DTI scan using FSL commands but its specific for Philips par rec files. You will need to modify this script for your specific acquisition.
Todd Richards
-----Original Message-----
From: FSL - FMRIB's Software Library [mailto:[log in to unmask]] On Behalf Of Forrest Johnson
Sent: Wednesday, June 16, 2010 8:39 AM
To: [log in to unmask]
Subject: [FSL] Gradient Field Map & Eddy Current Correction
Hello Experts,
I was wondering if someone could tell me if I apply my gradient field map correction before or after I run the eddy current correction in my DTI data? Also, if someone could provide a reference article that would be absolutely fabulous.
Also, do I need to motion correct the gradient field map?
Cheers
#!/bin/sh
SEARCHFOR=fMRI:DTI:B0:MPRAGE
#echo $SEARCHFOR
# Save current location
MYLOCAT=`pwd`
echo $MYLOCAT
TEST=`awk {print} ${1}` ;
#echo TEST:${TEST}
for AFOLDER in ${TEST}
do
if [ ! -d ${AFOLDER} ] ; then
echo
echo ERROR: Skipping this line of submit file
echo Can not CD to ${AFOLDER} from:
pwd
continue
fi
cd ${AFOLDER}
echo Working in Folder: ${AFOLDER}
PARSTOPROCESS=`ls *.PAR`
#echo $PARSTOPROCESS
for AFILE in ${PARSTOPROCESS}
do
#Strip off the extension
AFILE=`echo ${AFILE} | awk ' { keep=index($0,".PAR")-1 ; print substr($0, 1, keep) } ' ` ;
PROTOCOL=`awk ' /Protocol name/ { numsearch=split( "'${SEARCHFOR}'" , protos, ":") ; for (anitem in protos) {tst=index($0,protos[anitem]); if (tst > 0) print protos[anitem] ;} }' ${AFILE}.PAR `
# test if protocol not recognized;
if [ -z ${PROTOCOL} ]; then
echo
echo ERROR: Protocol not cognized for File: ${AFILE}
continue
fi
# test if this file has already been processed
if [ \( -e _${PROTOCOL}_${AFILE}.nii.gz \) -o \( -e \_${PROTOCOL}_MAG_${AFILE}.nii.gz \) ] ; then
#skip to next item in list for this folder
echo File: _${PROTOCOL}_${AFILE}.nii.gz already exists
continue
fi
echo ${AFILE} in folder ${AFOLDER} is a ${PROTOCOL} Protocol
#echo The PAR file contains a ${PROTOCOL} Protocol
SLICES=`awk '/Max. number of slices\/locations/ {print $7} ' ${AFILE}.PAR` ;
#echo Slices: $SLICES;
VOLS=`awk ' /Max. number of dynamics/ {print $7} ' ${AFILE}.PAR ` ;
#echo Volumes: $VOLS
DIMS=`awk ' /1 1 1 1/ {print $10, $11, $12, $13, $23, $24, $29, $30} ' ${AFILE}.PAR ` ;
#echo VoxelInfo: $DIMS
XDIM=`echo ${DIMS} | awk '{print $1}'`;
echo XDIM: ${XDIM}
XSIZE=`echo ${DIMS} | awk '{print $7}'`;
#echo XSIZE: ${XSIZE}
YDIM=`echo ${DIMS} | awk '{print $2}'`;
#echo YDIM: ${YDIM}
YSIZE=`echo ${DIMS} | awk '{print $8}'`;
#echo YSIZE: ${YSIZE}
ZSIZE=`echo ${DIMS} | awk '{print $5+$6}'`;
#echo ZSIZE: ${ZSIZE}
TR=`awk ' /Repetition time/ {print $6/1000} ' ${AFILE}.PAR ` ;
#echo TR: $TR
case "$PROTOCOL" in
fMRI)
#. Protocol name : fMRI_SSh CLEAR_TE30_BW2083P5_TR3_DYN114 CLEAR
#. Max. number of slices/locations : 32
#. Max. number of dynamics : 114
#. FOV (ap,fh,rl) [mm] : 240.00 159.00 240.00
#. Repetition time [ms] : 3000.00
# 1 1 1 1 0 2 0 16 100 64 64 0.0 1.632 4.815e-004 1000 2000 0.0 0.0 0.0 -3.3 -48.5 1.5 4.0 1.0 0 1 0 2 3.750 3.750 30.0 0.0 0.0 0.000 1 90.0 0 0 0 0 0.0
XYDIM=`echo ${DIMS} | awk '{print $1*$2}'`;
echo XYDIM: ${DIMS}
echo VOLS: $VOLS
echo SLICES: $SLICES
# create a header for xy t z
avwcreatehd ${XYDIM} ${VOLS} ${SLICES} 1 ${XSIZE} ${YSIZE} ${ZSIZE} ${TR} 0 0 0 4 rj_1.hdr
# Match this header to the input data
cp ${AFILE}.REC rj_1.img
#Swap the z and t dimensions
avwswapdim rj_1 x z y rj_2
# Force Output to ANALYZE format
avwchfiletype ANALYZE rj_2
# create a header for x y z t
avwcreatehd ${XDIM} ${YDIM} ${SLICES} ${VOLS} ${XSIZE} ${YSIZE} ${ZSIZE} ${TR} 0 0 0 4 rj_3.hdr
cp rj_2.img rj_3.img
#avwchfiletype NIFTI_GZ rj_3
avwswapdim rj_3 x -y z rj_4
#fslview rj_4
RI=`echo ${DIMS} | awk '{print $3}'`;
#echo RI: ${RI}
RS=`echo ${DIMS} | awk '{print $4}'`;
#echo RS: ${RS}
# DV = PV * RS + RI
avwmaths rj_4 -mul ${RS} -add ${RI} _${PROTOCOL}_${AFILE}
#fslview _${PROTOCOL}_${AFILE}
;;
B0)
#. Protocol name : B0_MAP_TE20_24_BW144P8
#. Max. number of slices/locations : 32
#. Max. number of dynamics : 1
#. FOV (ap,fh,rl) [mm] : 240.00 159.00 240.00
# 1 1 1 1 0 2 0 16 100 64 64 0.0 1.221 1.811e-004 1000 2000 0.0 0.0 0.0 -3.3 -48.5 1.5 4.0 1.0 0 1 0 2 3.750 3.750 20.0 0.0 0.0 0.000 1 90.0 0 0 0 0 0.0
# 1 1 1 1 3 4 32 16 100 64 64 -125.0 0.061 1.638e+001 0 250 0.0 0.0 0.0 -3.3 -48.5 1.5 4.0 1.0 0 1 0 2 3.750 3.750 20.0 0.0 0.0 0.000 1 90.0 0 0 0 0 0.0
# test if this is the B0 file that actually has some data
if [ -s ${AFILE}.REC ] ; then
# create a header for x y z t
avwcreatehd ${XDIM} ${YDIM} ${SLICES} 2 ${XSIZE} ${YSIZE} ${ZSIZE} ${TR} 0 0 0 4 rj_3.hdr
cp ${AFILE}.REC rj_3.img
avwswapdim rj_3 x -y z rj_4;
#fslview rj_4
MAG_RI=`echo ${DIMS} | awk '{print $3}'`;
# echo MAG_RI: ${MAG_RI}
MAG_RS=`echo ${DIMS} | awk '{print $4}'`;
# echo MAG_RS: ${MAG_RS}
PHASE_RI=`echo ${DIMS} | awk '{print $11}'`;
# echo PHASE_RI: ${PHASE_RI}
PHASE_RS=`echo ${DIMS} | awk '{print $12}'`;
# echo PHASE_RS: ${PHASE_RS}
avwsplit rj_4 rj
# DV = PV * RS + RI
avwmaths_32R rj0000 -mul ${MAG_RS} -add ${MAG_RI} rj0000
avwmaths_32R rj0001 -mul ${PHASE_RS} -add ${PHASE_RI} -mul 6.28318 rj0001
avwmerge -t rj_5 rj0000 rj0001
avwchfiletype ANALYZE rj_5
avwcreatehd ${XDIM} ${YDIM} ${SLICES} 2 ${XSIZE} ${YSIZE} ${ZSIZE} ${TR} 0 0 0 16 rj_6.hdr
cp rj_5.img rj_6.img
avwchfiletype NIFTI_GZ rj_6
avwsplit rj_6 rj
cp rj0000.nii.gz _B0_MAG.nii.gz
cp rj0001.nii.gz _B0_PHASE.nii.gz
# fixit to the right directory for designdti.fsf
cp /usr/local/fsl/bin/designdti.fsf local.fsf
echo 'set unwarp_files(1) "'${AFOLDER}'/_B0_PHASE.nii.gz"' >> local.fsf
echo 'set unwarp_files_mag(1) "'${AFOLDER}'/_B0_MAG.nii.gz"' >> local.fsf
echo 'set feat_files(1) "'${AFOLDER}'/dtidata.nii.gz"' >> local.fsf
# Change the working directory setup by todd
cat local.fsf
else
echo Skipping file ${AFILE} because the REC file has 0 bytes
continue
fi
;;
DTI)
#. Protocol name : DTI_SSh_BW932_TE63_DIFFGR_32P7 SENSE
#. Max. number of slices/locations : 72
#. Max. number of dynamics : 258
#. FOV (ap,fh,rl) [mm] : 240.00 144.00 240.00
# 1 1 33 1 0 1 0 16 100 128 128 0.0 2.907 1.295e-003 1064 2128 0.0 0.0 0.0 -3.3 -40.2 1.5 2.0 0.0 0 1 0 2 1.875 1.875 63.0 0.0 0.0 0.000 1 90.0 0 0 0 0 0.0
DIMS=`awk ' /1 1 1 0 1 / {print $10, $11, $12, $13, $23, $24, $29, $30, $3, $34, $46, $47, $48} ' ${AFILE}.PAR ` ;
# echo VoxelInfo: $DIMS
XDIM=`echo ${DIMS} | awk '{print $1}'`;
echo XDIM: ${XDIM}
XSIZE=`echo ${DIMS} | awk '{print $7}'`;
echo XSIZE: ${XSIZE}
YDIM=`echo ${DIMS} | awk '{print $2}'`;
echo YDIM: ${YDIM}
YSIZE=`echo ${DIMS} | awk '{print $8}'`;
echo YSIZE: ${YSIZE}
ZSIZE=`echo ${DIMS} | awk '{print $5+$6}'`;
echo ZSIZE: ${ZSIZE}
XYDIM=`echo ${DIMS} | awk '{print $1*$2}'`;
echo XYDIM: ${XYDIM}
VOLS=34;
echo VOLS: ${VOLS}
echo SLICES: ${SLICES}
# create a header for xy t z
fslcreatehd ${XDIM} ${YDIM} ${SLICES} ${VOLS} ${XSIZE} ${YSIZE} ${ZSIZE} ${TR} 0 0 0 16 test34
fslchfiletype ANALYZE test34
# Match this header to the input data
cp ${AFILE}.REC rj_1.img
rm sendname.txt
echo "${AFILE}.PAR" >> sendname.txt
/usr/local/fsl/bin/findbvecdonna.exe
cp rj_1a.img ${AFILE}dti.img
cp test34.hdr ${AFILE}dti.hdr
cp bvecs.txt bvecs
cp bvals.txt bvals
eddy_correct ${AFILE}dti.hdr dtidata 0
;;
esac
done
# done with converting B0 and DTI to nifti
# now process DTI data with B0 map
# Todd changed this part to fix the brain cut off problem by using
# bet with -f 0.3
feat local.fsf
cp ./dtidata.feat/filtered_func_data.nii.gz ./unwarpdtidata.nii.gz
fslroi ./unwarpdtidata ./nodif 0 1
bet ./nodif ./nodif_brain_mask1 -f 0.3
fslmaths ./nodif_brain_mask1 -bin ./nodif_brain_mask
fslroi ./unwarpdtidata ./data2 0 33
dtifit -k ./data2 -m ./nodif_brain_mask -r bvecs -b bvals -o ./dti
# Now back to calling folder
cd ${MYLOCAT}
done
exit
|