Gradient Gradient Non-linearity Correction Software Package

Author: Silvester Czanner (see also: SilvesterNotes)

  1. Overview of distortion correction code
  2. Limitations of the code
  3. Contents in distribution
  4. Setting up local environment variables for use
  5. Use instructions
  6. Support and contacts
  7. Acknowledgements

1. Overview of distortion correction code

To correct for image distortions in MRI data due to non-linearity of the magnetic fields from the imaging gradient coils.

Described in: Jovicich J, Czanner S, Greve D, Haley E, Kouwe A, Gollub R, Kennedy D, Schmitt F, Brown G, MacFall J, Fischl B, Dale A. Reliability in Multi-Site Structural MRI Studies: Effects of Gradient Non-linearity Correction on Phantom and Human Data. NeuroImage NeuroImage (Apr 1;30(2):436-43, 2006)

Outline of steps involved:

  1. Obtain from your local Siemens or GE vendor the spherical harmonics expansion that represents the gradient coils used in the MRI system you want to correct. This is a text file with proprietory information.
  2. We provide a script ( ) that reads the spherical harmonics text file and writes out the coefficients in a standard format (for example, avanto.coef).
  3. We provide a script (create_displacement_table) that reads in the standard formatted coefficients (e.g., avanto.coef) of your system and writes out a file that has the tables for displacements along the x,y,z axes and also the intensity correction table due to voxel size distortion (e.g., avanto.gwv).
  4. We provide a script (grad_unwarp) that reads in the correction tables of your system and the dicom image volume you want to correct and writes out the distortion corrected dicom volume. For more details on other image formats see Use instructions.

2. Limitations of the code

3. Contents of distribution

The whole distribution package contains 5 subdirectories:

4. Setting up local environment variables

You need to set up the following two variables:

Setup the environment variable GRAD_UNWARP_DIR to the grad_unwarp_bash directory. For example:

Setup the variable MATLAB to the path of your matlab executable file For example:

With these environments you can define aliases to run the scripts:

And then just run the scripts by typing:

5. How to use it

Script is used to convert Siemens .grad or GE .dat to .coef, which is needed to create the displacement table.


perl <filename>

perl bay1-gw_coils.dat
  • perl coeff_AS05.grad

Script create_displacement_table is used to create a displacement table (*.gwv). It has 2 parameters: vendor and table name. Supported vendor names are siemens and ge. Allowed table names are avanto, sonata, brm, crm. Meaningful combinations are siemens (avanto or sonata), ge (brm or crm)

create_displacement_table vendor table_name
create_displacement_table siemens sonata
  • create_displacement_table ge crm

Script is reading file with the 1st harmonic coefficients (*.coef) from $GRAD_UNWARP_DIR/grad_unwarp_tables and calculates the displacement table. The table is saved into $GRAD_UNWARP_DIR/grad_unwarp_tables directory.

Script grad_unwarp is used to unwarp the warped raw images produced by scanner devices. It uses several options. If you are not sure about the options, just type

alias grad_unwarp $GRAD_UNWARP_DIR/scripts/grad_unwarp grad_unwarp


grad_unwarp -help

Grad_unwarp script has been tested with avanto, sonata, brm and crm MGH phantom files and with brm dicom files (series #6). You can find the testing data files in

$GRAD_UNWARP_DIR/sample_phantom_data $GRAD_UNWARP_DIR/sample_phantom_data/dicom_BRM_ucsd

6. H E L P

grad_unwarp is an unwarping tool. It provides a full 3D unwarping for data from Siemens devices. For data from GE devices there is an assumption that these data are already in-plane dewarped.

There are four gradient-coil types supported at the moment: GE BRM, GE CRM, Siemens Sonata/Trio, Siemens Avanto, Siemens Allegra. For each of these, there is a large file somewhere that is an offsets table - for outvol voxel here, look there in invol. Interpolation in the offsets table is trilinear; interpolation in the input volume may be specified by the user with -interp foo. Default is cubic.

There are three ways to use the grad_unwarp flag -unwarp <type>.

A jacobian brightness correction is applied by default - areas of the image that spread out (increase in volume) should dim (decrease in intensity). If for some reason you wish to skip that step, use the -nojac option.

7. E X A M P L E S

grad_unwarp -i avanto.mgh -o avanto_uw.mgh -unwarp avanto

it will read data stored in avanto.mgh and produce a new dewarped data file avanto_uw.mgh . The dewarping will be done based on displacement table stored in file avanto.gvw

grad_unwarp -i dicom_BRM_ucsd/001.dcm -s 6 -o brm_ucsd_uw.mgh -unwarp brm

it will read the data from DICOM file, serie #6 from directory dicom_BRM_ucsd/, dewarp it and create new data file brm_ucsd_uw.mgh in MGH format

8. MGH data file Viewer

There is a simple MGH/MGZ/DICOM data file viewer written in matlab. To use it, you have to run matlab, add new path $GRAD_UNWARP_DIR/matlab and type mgh_viewer in matlab's command window. It will create and open an User interface.

8. Support and contacts

Support is very limited but we will do our best to try to answer your questions. Please email your constructive comments to: