← Vincent Groenhuis

MRI geometric distortion: calibration cube

Esaote G-scan Brio (0.25 T), 3D HYCE sequence, 256 × 256 × 164 voxels of 1.055 mm. Scanned at the University of Twente, May 2022. The phantom contains small markers on a regular 3D grid with 20 mm spacing. Comparing where the scanner shows them with where they really are gives the geometric distortion, which is modelled by a 5th order polynomial.

Why a custom method? The scanner's own software can correct geometric distortion in 2D (within each slice), but not in 3D. For 3D acquisitions the through-plane component and its variation across slices stay uncorrected. A custom measurement and correction method was therefore needed to compensate for the distortion in all three dimensions.

3D viewer

Drag to rotate, scroll to zoom, hover a dot for its details. Coordinates are DICOM patient coordinates (LPS) in mm, see coordinate system. The letters L/R, A/P and S/I in the view mark the anatomical directions. Distortion vectors and the deformed lattice can be exaggerated to make the pattern easier to see.

Layers

Slice position (mm)

x
y
z
◐

Exaggeration

×

View

The scan slices show the image as acquired, i.e. still distorted. Measured dots sit on the bright spots; the true grid is where they should have been.
Loading scan and results…

Distortion versus distance from isocentre

Each dot's displacement from its true position, before and after applying the polynomial correction. Distortion grows quickly towards the edge of the field of view.

Statistics per spherical volume

Statistics for all dots within a sphere of the given radius around the isocentre (true position).

Coordinate system: XYZ, LPS and RAS

All x, y, z values on this page and in the data files are DICOM patient coordinates, taken directly from the DICOM headers (ImagePositionPatient, ImageOrientationPatient = [1 0 0 0 1 0], PixelSpacing). DICOM defines this frame as LPS:

AxisLPS (DICOM, ITK, this page)RAS (3D Slicer, NIfTI, FreeSurfer)Voxel index → mm
x+x towards patient LeftxRAS = −x (towards Right)x = −135 + 1.0547 · column
y+y towards PosterioryRAS = −y (towards Anterior)y = −135 + 1.0547 · row
z+z towards Superior (head)zRAS = z (unchanged)z = −85.98 + 1.055 · slice

Converting a point between LPS and RAS is just flipping the sign of x and y. The origin (0, 0, 0) is the same in both. Here it is the centre of the field of view, presumably the magnet isocentre.

Relation to the room. The anatomical labels refer to the patient position entered at the console, here Feet First Supine (FFS), also for a phantom. For a supine patient posterior is down, so +y points towards the floor. At 0° tilt the main field B0 of the G-scan is vertical, i.e. along y. With feet first, +z (superior) points towards the side of the magnet from which the patient entered. Had the scan been registered as Head First Supine, x and z would point the other way in the room. Switch on Scanner, bed & floor in the viewer to see this.

Converting the polynomial. The coefficients cannot simply be relabelled: in RAS the mapping becomes PRAS(r) = D · PLPS(D · r) with D = diag(−1, −1, 1), which changes the sign of some coefficients. Both versions are provided in polynomials.json (keys lps and ras).

Method

Segmentation. The volume is smoothed slightly, a slowly varying background is subtracted, and the result is thresholded. Connected components of 4–200 voxels are dot candidates; the larger bars and cubes (placed in the phantom so the scanner can calibrate itself) are rejected. Each dot's centre is its intensity-weighted centroid.

Grid identification. The dot closest to the scanner origin gets grid index (0, 0, 0). From every identified dot, the six neighbours are predicted 20 mm away, extrapolating the local step from the opposite neighbour so the search follows the distortion. The nearest candidate within 6 mm is accepted. Dots are processed in order of increasing distance to the origin, so the grid grows outwards from the well-behaved centre.

True positions. The ideal 20 mm lattice is rigidly registered (rotation and translation) to the dots within 60 mm of the isocentre, where gradient non-linearity is negligible.

Polynomial fit. Two 5th order 3D polynomials (56 terms per coordinate) are fitted by least squares: a correction that maps distorted image coordinates to true coordinates, and a forward model that maps true coordinates to where they appear in the image. Coordinates are scaled by 100 mm for numerical conditioning.

Using the correction polynomial

The correction polynomial maps a position as it appears in the image (distorted) to its true position. Each output coordinate is a separate polynomial in x, y and z:

x′ = Σk=1…56 ck,x · (x/s)ak · (y/s)bk · (z/s)ck   and likewise y′ (ck,y) and z′ (ck,z)
(x, y, z): distorted position in mm · (x′, y′, z′): true position in mm · s = 100 mm · the 56 exponent triples (ak, bk, ck) are all non-negative integers with a + b + c ≤ 5.

The forward polynomial has the same form and does the opposite: true position → position in the image. Exponents and coefficients for both, in LPS and RAS, are in polynomials.json.

import json
import numpy as np

def load(path="polynomials.json", frame="lps", kind="correction"):
    p = json.load(open(path))[frame][kind]          # frame: "lps" or "ras"
    return np.array(p["exponents"]), np.array(p["coefficients_xyz"]), p["scale_mm"]

def evaluate(poly, xyz):
    """Map (N, 3) positions in mm to (N, 3) positions in mm."""
    exponents, coef, s = poly
    u = np.atleast_2d(np.asarray(xyz, float)) / s
    out = np.zeros_like(u)
    for (a, b, c), ck in zip(exponents, coef):
        out += np.outer(u[:, 0]**a * u[:, 1]**b * u[:, 2]**c, ck)
    return out

correction = load(kind="correction")
print(evaluate(correction, [[50.0, 30.0, -20.0]]))  # distorted -> true (LPS, mm)

Try it

Correction (image → true):
Forward (true → image):
Coefficient tables