This is an old revision of the document!
Table of Contents
EPI Correction with polarity images using TOPUP
Steps to setup and apply FSL Topup correction on EPI data collected here with the use of your polarity images
Create your acquisition parameters
There will be two series of single timepoint EPI images. You can grab relevant info to create the acq_params.txt files from your XML header.
You need to calculate readout time in seconds ( the physical time it takes to get the acquisition matrix of a single slice ) and get the polarity direction ( phase encode direction ).
the readout time in seconds for the parameter file will be:
readout = (echospacing * (acquisitionmatrix[0] * (percentsampling/100))) / 1e6 echospacing in the BXH header is in microseconds
the polarity for the entry will have to be determined from the seriesdescription, which is typically “field map reverse polarity” or “field map regular”
reverse will be “-1” in the acq_params.txt and regular will be “1”
echo '0 1 0 readout' > acq_params.txt echo '0 -1 0 readout' >> acq_params.txt example output: 0 1 0 0.077312 0 -1 0 0.077312
Create your Blip Up/Down image
Merge the two polarity images together into a 4D file with fsl_merge. Put them in the order of your acq_params.txt file. In the example above, it would be regular, then reversed.
fslmerge -t bud ../bia6_00186_006.nii.gz ../bia6_00186_007.nii.gz tesla:00273 cmp12$ fslinfo bud.nii.gz data_type INT16 dim1 128 dim2 128 dim3 70 dim4 2
Run topup to calculate the field and coefficients images for correction
#run popup calculate the field/coef topup --verbose --imain=bud --datain=acq_params.txt --config=$FSLDIR/src/topup/flirtsch/b02b0.cnf --out=rs_topup --fout=topup_field
Now apply the correction to your functional runs
inindex references the “regular” image index from your acq_params.txt file, which is the same phase encode direction of your functional runs
#apply it applytopup --imain=../bia6_00186_008_01.nii.gz --inindex=1 --method=jac --datain=acq_params.txt --topup=rs_topup --out=run008 --verbose applytopup --imain=../bia6_00186_009_01.nii.gz --inindex=1 --method=jac --datain=acq_params.txt --topup=rs_topup --out=run009 --verbose applytopup --imain=../bia6_00186_010_01.nii.gz --inindex=1 --method=jac --datain=acq_params.txt --topup=rs_topup --out=run010 --verbose
The top two images are an example of the polarity images after correction, which is not necessary. The bottom two images are the mean functional image of a series uncorrected, then corrected by the topup results.
If you want to re-generate a valid BXH for the corrected data, you can generate a new BXH and merge in the original info
fslwrapbxh run008 mv run008.bxh tmp.bxh bxh_merge ../bia6_00186_008_01.bxh tmp.bxh run008.bxh rm tmp.bxh
DWI Correction with RPE B0s using TOPUP
Correcting DWI images using reverse phase encoded B0s is almost the same as the above. Typically you'll have a couple B0s in your normal DWI acquisition, with a separate series of the same number of B0s collected with the phase encoding direction reversed.
Create your acq_params.txt file
the readout time in seconds for the parameter file will be:
readout = (echospacing * (acquisitionmatrix[0] * (percentsampling/100))) / 1e6 echospacing in BXH header is in microseconds
the regular B0s will get the “1” and the reverse phase B0s will get the “-1”
echo '0 1 0 [readout]' > acq_params.txt echo '0 1 0 [readout]' >> acq_params.txt echo '0 -1 0 [readout]' >> acq_params.txt echo '0 -1 0 [readout]' >> acq_params.txt example output: 0 1 0 0.10656 0 1 0 0.10656 0 -1 0 0.10656 0 -1 0 0.10656
Create your Blip Up/Down image
First, you'll need to extract your B0s from the regular DWI acquisition.
If you look at the gradient directions within the DWI acquisition the B0s will be “0 0 0”.
Within the BXH the first 2 directions are B0:
<datapoints label="diffusiondirection"> <value>0 0 0</value> <value>0 0 0</value> <value>0.707107 0 0</value> <-- not a B0
Extract them with bxhselect:
bxhselect --timeselect 0:1 bia6_00197_012.bxh bu bxhselect --timeselect 0:1 bia6_00197_013.bxh bd
This will create bu.nii.gz / bd.nii.gz with the first 2 gradient directions ( the B0s )
Now merge the extracted B0s from the regular acquisition with the images from the reversed acquisition. Merge these in the same order of the acq_params.txt file.
fslmerge -t bud bu.nii.gz bd.nii.gz tesla:HCP cmp12$ fslinfo bud.nii.gz data_type INT16 dim1 256 dim2 256 dim3 92 dim4 4
Run topup to calculate the field and coefficients images for correction
#run popup calculate the field/coef topup --verbose --imain=bud --datain=acq_params.txt --config=$FSLDIR/src/topup/flirtsch/b02b0.cnf --out=dwi_topup --fout=topup_field
Now apply the correction to your DWI
inindex references the “regular” dwi B0s index from your acq_para ms. txt file
#apply it applytopup --imain=bia6_00197_012.nii.gz --inindex=1 --method=jac --datain=acq_params.txt --topup=dwi_topup --out=dwi_corrected --verbose
If you want to re-generate a valid BXH for the corrected data, you can generate a new BXH and merge in the original info
fslwrapbxh dwi_corrected.nii.gz mv dwi_corrected.bxh tmp.bxh bxh_addgradients --fsl tmp.bxh bvecs bvals dwi_corrected.bxh rm tmp.bxh
DWI Correction with MRTRIX3 and RPE Data
mrtrix3 has a nice wrapper for FSL's eddy/topup/apply_topup that can do the above corrections and along with eddy corrections
Calculate your readout time
readout = (echospacing * (acquisitionmatrix[0] * (percentsampling/100))) / 1e6 echospacing in BXH header is in microseconds
Prepare your input datasets
there are 2 scenarios that typically apply here 1) a short acquisition with RPE B0s 2) an entire acquisition with the same gradient table and reverse phase encoding
Scenario 1
For scenario 1, create your blip up / blip down B0 data the same way as above.
bxhselect --timeselect 0:1 bia6_00197_012.bxh bu bxhselect --timeselect 0:1 bia6_00197_013.bxh bd fslmerge -t bud bu.nii.gz bd.nii.gz <code> Prepare your dwi series for input to mrtrix3. If you use their mif data format, then the gradient tables will be automatically passed throughout their software with additional flags. <code> #pull the gradient table from BXH in FSL format extractdiffdirs --fsl bia6_00414_013.bxh bvecs bvals #convert nii.gz data into mif while inserting the gradients mrconvert -fslgrad bvecs bvals bia6_00414_013.nii.gz dwi.mif #you can verify the table tesla:00414 cmp12$ mrinfo dwi.mif -dwgrad 0 0 0 0 0 0 0 0 1 0 0 1500 0.456784 0.889578 0 1501.42 -0.264866 0.484757 0.833581 1501.51 0.937268 -0.284081 0.202058 1499.14 0.0630209 -0.806262 0.588192 1499.02 -0.679047 -0.0940064 0.72805 1499.79 0.686982 0.278993 0.670983 1500.08 -0.232946 0.949777 0.208951 1500.7 0.922569 0.178916 0.341841 1501.4 -0.111021 -0.980188 -0.164032 1499.43 -0.132016 -0.854107 -0.503064 1499.62