Hello,
I am responsible for most of the content of this repository, and got guidance implementing the distortion correction tools from various members of the AFNI team.
The B[sub]0[/sub] correction module using AFNI tools runs from approximately lines 250 to 300 in the “distortionFix.py” file.
The input to this module are a BIDS ID for 1 subject’s data for a given session, the magnitude image from a B[sub]0[/sub] field map acquisition, the frequency map from the B[sub]0[/sub] field map acquisition (essentially a scaled phase map - more details below), a mask of the B[sub]0[/sub] (usually generated by running 3dAutomask on the magnitude B[sub]0[/sub] data), the effective echo spacing between lines of EPI acquisition (in seconds), and the EPI phase FOV (in mm).
The first step here is to take the information in the frequency map, scale it “appropriately”, according to the following formula:
Frequency Map * EPI Echo Spacing (in seconds) * EPI Phase FOV (in mm)
The field map is then smoothed using gaussian blurring.
The scaled and smoothed field map is then used to “self distort” - so that its distortions now match the EPI distortions. This is the “fmapInHz-smoothed-warped2epi_” data set.
Finally, this distorted field map is used to unwarp the EPI data.
In addition to the timing and geometric data put in above, you would also need to know your phase encoding direction. As far as I know, the vendors don’t have a standard way to denote +y / -y / +AP / -AP. I would say try both orientations on a handful of subjects - it should be pretty apparent which is correct from the visual changes in distortion. Once you’ve figured this out, and the acquisition for your study remained consistent, this should “just work”.
As to integration with the AFNI processing stream, I’ve not done this work. The distorted field map generated above is essentially another warp field that should be able to be concatenated with other warps, but I think other members of the AFNI team can better answer that particular part of your question.
Glad you found this repository - and hope you can use the methods in there!
Vinai