biac:analysis:topup_correction
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
biac:analysis:topup_correction [2019/02/19 16:26] – cmp12 | biac:analysis:topup_correction [2019/02/22 14:51] – cmp12 | ||
---|---|---|---|
Line 3: | Line 3: | ||
Steps to setup and apply [[https:// | Steps to setup and apply [[https:// | ||
- | == Create your acquisition parameters == | + | ==== Create your acquisition parameters |
- | There will be two series of single timepoint EPI images. | + | There will be two series of single timepoint EPI images. |
- | You need to calculate | + | You need to calculate |
+ | |||
+ | the readout time in seconds for the parameter file will be: | ||
+ | < | ||
+ | |||
+ | echospacing in the BXH header is in microseconds | ||
+ | </ | ||
- | the ETL for the parameter file will be: | ||
- | < | ||
the polarity for the entry will have to be determined from the **seriesdescription**, | the polarity for the entry will have to be determined from the **seriesdescription**, | ||
Line 17: | Line 21: | ||
< | < | ||
- | echo ' | + | echo '0 1 0 readout' > acq_params.txt |
- | echo '0 1 0 [ETL]' >> acq_params.txt | + | echo ' |
example output: | example output: | ||
- | | + | 0 1 0 0.077312 |
- | 0 1 0 0.604 | + | |
</ | </ | ||
- | == Create your Blip Up/Down image == | + | ==== 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 reversed, then regular. | + | 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. |
< | < | ||
Line 41: | Line 45: | ||
</ | </ | ||
- | == Run topup to calculate the field and coefficients images for correction == | + | {{: |
+ | |||
+ | ==== Run topup to calculate the field and coefficients images for correction | ||
< | < | ||
Line 48: | Line 54: | ||
</ | </ | ||
- | == Now apply the correction to your functional runs == | + | ==== Now apply the correction to your functional runs ==== |
+ | **inindex** references the " | ||
< | < | ||
#apply it | #apply it | ||
Line 54: | Line 62: | ||
applytopup --imain=../ | applytopup --imain=../ | ||
applytopup --imain=../ | applytopup --imain=../ | ||
+ | </ | ||
+ | |||
+ | 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, | ||
+ | |||
+ | {{: | ||
+ | |||
+ | 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 ../ | ||
+ | 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. | ||
+ | |||
+ | ==== Create your acq_params.txt file === | ||
+ | |||
+ | the readout time in seconds for the parameter file will be: | ||
+ | < | ||
+ | |||
+ | echospacing in BXH header is in microseconds | ||
+ | </ | ||
+ | |||
+ | the regular B0s will get the " | ||
+ | |||
+ | < | ||
+ | echo '0 1 0 [readout]' | ||
+ | echo '0 1 0 [readout]' | ||
+ | echo '0 -1 0 [readout]' | ||
+ | echo '0 -1 0 [readout]' | ||
+ | |||
+ | 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: | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | 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. | ||
+ | < | ||
+ | fslmerge -t bud bu.nii.gz bd.nii.gz | ||
+ | |||
+ | tesla:HCP cmp12$ fslinfo bud.nii.gz | ||
+ | data_type | ||
+ | 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/ | ||
+ | </ | ||
+ | |||
+ | ==== Now apply the correction to your DWI ==== | ||
+ | |||
+ | **inindex** references the " | ||
+ | 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 ====== | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | If you are running dwidenoise, do it BEFORE dwipreproc. | ||
+ | |||
+ | ==== Calculate your readout time ==== | ||
+ | < | ||
+ | |||
+ | echospacing in BXH header is in microseconds | ||
+ | </ | ||
+ | |||
+ | ==== Prepare your input datasets ==== | ||
+ | |||
+ | there are 2 scenarios that typically apply here | ||
+ | 1) DWI and a short acquisition with RPE B0s | ||
+ | 2) 2 entire acquisitions with the same gradient table and reverse phase encoding | ||
+ | |||
+ | In both scenarios it is important to create your data with normal phase encoding direction first, followed by reversed. | ||
+ | |||
+ | ===== Scenario 1 ===== | ||
+ | |||
+ | ==== Prepare your input datasets ==== | ||
+ | |||
+ | Specify that a set of images (typically b=0 volumes) will be provided for use in inhomogeneity field estimation only | ||
+ | |||
+ | For scenario 1, create your blip up / blip down B0 data the same way as above. | ||
+ | < | ||
+ | bxhselect --timeselect 0 bi | ||
+ | a6_00197_012.bxh bu | ||
+ | bxhselect --timeselect 0 bia6_00197_013.bxh bd | ||
+ | fslmerge -t bud bu.nii.gz bd.nii.gz | ||
+ | rm bu.* bd.* | ||
+ | </ | ||
+ | |||
+ | Prepare your dwi series for input to mrtrix3. | ||
+ | |||
+ | < | ||
+ | #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 | ||
+ | |||
+ | #export the table back out in their format | ||
+ | mrinfo dwi.mif -export_grad_mrtrix grads.b | ||
+ | |||
+ | #put THOSE back into the mif header | ||
+ | mrconvert -grad grads.b dwi.mif dwi.mif -force | ||
+ | |||
+ | </ | ||
+ | |||
+ | The last step seems redundant, but there is an issue with how mrtrix3 tools are handling the multi-shell GE data produced on our scanners. | ||
+ | |||
+ | ==== Run dwipreproc -rpe_pair ==== | ||
+ | |||
+ | Run [[https:// | ||
+ | |||
+ | < | ||
+ | dwipre | ||
+ | proc dwi.mif dwi_corr.mif -rpe_pair -se_epi bud.nii.gz -pe_dir AP -readout_time 0.10656 | ||
+ | |||
+ | -rpe_pair specifies you're providing a pair of B0s ( regular, reversed ) | ||
+ | -se_epi is you bud image | ||
+ | -pe_dir is your dwi's phase encode direction | ||
+ | -readout_time is from calculation above | ||
+ | </ | ||
+ | |||
+ | dwipreproc will run topup, eddy and apply topup. | ||
+ | |||
+ | You can generate a BXH header for a mif file with: | ||
+ | < | ||
+ | mif2bxh dwi_corr.mif dwi_corr.bxh | ||
+ | </ | ||
+ | |||
+ | ===== Scenario 2 ===== | ||
+ | |||
+ | You have an entire acquisition with the same gradient table as your DWI sequence, but with reverse phase encoding. | ||
+ | |||
+ | Calculate the readout time in the same way as above | ||
+ | |||
+ | ==== Prepare your input datasets ==== | ||
+ | |||
+ | This time you'll concatenate the 2 DWI acquisitions. | ||
+ | |||
+ | < | ||
+ | #concat the 2 series ( regular, reversed ) | ||
+ | bxh_concat bia6_00260_007_LAS.bxh bia6_00260_008_LAS.bxh both | ||
+ | |||
+ | #extract the gradients | ||
+ | extractdiffdirs --fsl both bvecs bvals | ||
+ | |||
+ | #convert to mif | ||
+ | mrconvert -fslgrad bvecs bvals both.nii.gz dwi.mif | ||
+ | |||
+ | #re-extract table | ||
+ | mrinfo dwi.mif -export_grad_mrtrix grads.b | ||
+ | |||
+ | #put corrected table back in | ||
+ | mrconvert -grad grads.b dwi.mif dwi.mif -force | ||
+ | |||
+ | #remove the temporary files ( bvecs, bvals, both.* ) | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Run dwipreproc -rpe_all ==== | ||
+ | |||
+ | Run dwipreproc with the " | ||
+ | |||
+ | < | ||
+ | dwipreproc dwi.mif dwi_corr.mif -rpe_all -pe_dir AP -readout_time 0.10656 -debug | ||
+ | |||
+ | -rpe_all signals that you've replicated A | ||
+ | LL the directions with a rpe acquisition | ||
+ | -pe_dir is the phase encode direction of your regular acquisition | ||
+ | -readout_time from above | ||
</ | </ | ||
+ | {{ : | ||
biac/analysis/topup_correction.txt · Last modified: 2024/06/21 15:44 by 127.0.0.1