NMR and MRI physics · Intermediate

k-space: sampling and image formation

Written by SignalsLab

Early edition: these lessons are being reviewed.

Content

Summary

In MRI, the raw data are samples of the spatial Fourier transform of the object's transverse magnetization, called k-space. Gradients move the sampling position through k-space, and an inverse Fourier transform of the sampled data gives the image. The sampling spacing sets the field of view, and the extent of k-space sets the resolution.

Intuition

Each k-space point measures how strongly the object contains one spatial wave pattern, defined by a spatial frequency. Low-frequency points near the center carry overall brightness and contrast. High-frequency points at the edges carry fine detail and edges. A gradient makes spins at different positions precess at different rates, which winds up a phase pattern across the object. The signal we record is the sum of all spins with that phase twist, which is exactly one Fourier coefficient. By changing the gradient over time we visit different coefficients. Once we have enough of them on a regular grid, the inverse Fourier transform rebuilds the image. Sampling more finely in k means a larger field of view before aliasing. Reaching farther out in k means sharper resolution.

Key equations

k(t)=γ2π∫0tG(τ)dτ
(1)

k-space position is the accumulated gradient area (γ2π in Hz per tesla).

S(k)=∫ρ(x)e−i2πkxdx
(2)

The measured signal is the Fourier transform of the spin density rho(x).

ρ(x)=∫S(k)ei2πkxdk
(3)

The image is the inverse Fourier transform of the k-space data.

FOV=1Δk,Δx=12kmax=1NΔk
(4)

Sample spacing sets field of view; maximum k sets resolution (pixel size).

Derivation

  1. Start with spins at position x precessing at frequency γB0 plus γGx in the rotating frame, with gradient G on.
  2. The phase accumulated at x is ϕ(x,t)=−γx×∫Gdt, which equals −2πk(t)x.
  3. The coil sums signal from all positions: S(t)=∫ρ(x)exp⁡(−i2πk(t)x)dx.
  4. This is the Fourier transform of rho evaluated at k(t), so the received signal at time t is a sample of k-space at k(t).
  5. Sampling at N points spaced by Delta k is multiplication by a comb function, which replicates the image every 1/Delta k in space.
  6. To avoid overlap (aliasing), the object must fit inside FOV = 1/Delta k.
  7. Truncating k at plus or minus k_max is multiplication by a rectangle, so the image is blurred with a sinc of width about 1/(2 k_max), giving the resolution.
  8. Applying the inverse discrete Fourier transform to the N samples yields N pixels of size FOV/N.

Worked example

Problem

A 1D readout uses gradient G=10 mT/m, with γ2π=42.58 MHz/T. We sample N=256 points, with dwell time 20 microseconds. Find Δk, FOV, and pixel size.

  1. Delta k = (gamma/2pi) G Delta t = 42.58e6 Hz/T x 0.010 T/m x 20e-6 s.
  2. Compute: 42.58e6 x 0.010 = 4.258e5 Hz/m; times 20e-6 s gives 8.516 per meter (cycles/m).
  3. FOV = 1/Delta k = 1/8.516 = 0.1174 m, about 11.7 cm.
  4. Pixel size = FOV/N = 117.4 mm / 256 = 0.459 mm.

Answer Delta k ≈ 8.5 m^-1, FOV ≈ 11.7 cm, pixel size ≈ 0.46 mm.

Common mistakes

  • Thinking each k-space point corresponds to one image pixel; each point encodes a spatial frequency over the whole image.
  • Believing the edges of k-space give contrast; the center gives contrast and the periphery gives detail.
  • Confusing FOV with resolution: FOV depends on Delta k, resolution on k_max.
  • Forgetting that γ2π must be used when k is in cycles per meter.
  • Assuming a smaller Delta k lowers resolution; it enlarges the FOV.

Animation

Animation coming soon

The animated version of this lesson is being prepared for the web. In the Signals AI app, lessons are drawn step by step.

Code

scene.py(100 lines)
import sys
import numpy as np
from manim import *
from blocks import *


def make_phantom(n=32):
    """Simple phantom: bright disk with a smaller dark disk inside."""
    y, x = np.mgrid[0:n, 0:n]
    cx = cy = (n - 1) / 2
    r = np.hypot(x - cx, y - cy)
    img = np.zeros((n, n))
    img[r < n * 0.38] = 1.0
    img[np.hypot(x - cx - 5, y - cy + 3) < n * 0.12] = 0.3
    return img


def kspace(img):
    """Centered 2D FFT."""
    return np.fft.fftshift(np.fft.fft2(img))


def recon(k, radius):
    """Reconstruct from the k-space samples within radius of the center."""
    n = k.shape[0]
    y, x = np.mgrid[0:n, 0:n]
    c = n / 2
    mask = np.hypot(x - c, y - c) <= radius
    return np.real(np.fft.ifft2(np.fft.ifftshift(k * mask))), mask


def to_grid(a, cell, top_left, vmax):
    """Draw a 2D array as grayscale squares."""
    n = a.shape[0]
    g = VGroup()
    for i in range(n):
        for j in range(n):
            v = float(np.clip(a[i, j] / vmax, 0, 1))
            s = Square(cell, stroke_width=0, fill_color=interpolate_color(BLACK, WHITE, v),
                       fill_opacity=1)
            s.move_to(top_left + np.array([j * cell, -i * cell, 0]))
            g.add(s)
    return g


IMG = make_phantom()
K = kspace(IMG)
RADII = [2, 5, 16]
RECONS = [recon(K, r)[0] for r in RADII]
ERRS = [float(np.linalg.norm(R - IMG) / np.linalg.norm(IMG)) for R in RECONS]


class Main(Scene):
    def construct(self):
        self.camera.background_color = "#101418"
        TitleCard(self, "k-space", "sampling and image formation")
        cell = 0.115
        n = IMG.shape[0]
        size = cell * n
        kmag = np.log1p(np.abs(K))
        kmag = kmag / kmag.max()
        left = np.array([-5.0, 1.6, 0])
        right = np.array([1.2, 1.6, 0])
        kgrid = to_grid(kmag, cell, left, 1.0)
        kgrid.scale(1.0)
        lab_k = Text("k-space (log |S|)", font_size=24).next_to(kgrid, UP, buff=0.15)
        self.play(FadeIn(kgrid), FadeIn(lab_k))
        StepCaption(self, "Low k: contrast. High k: edges and detail.")
        arrow = Arrow(LEFT, RIGHT, color=C_ACCENT).move_to([-0.8, 0.0, 0]).scale(0.8)
        ifft = Text("inverse FFT", font_size=24, color=C_ACCENT).next_to(arrow, UP, buff=0.1)
        self.play(GrowArrow(arrow), FadeIn(ifft))
        shown = None
        for r, R, e in zip(RADII, RECONS, ERRS):
            g = to_grid(np.clip(R, 0, 1), cell, right, 1.0)
            lab = Text(f"radius {r}: error {e:.2f}", font_size=24, color=C_ACCENT)
            lab.next_to(g, UP, buff=0.15)
            ring = Circle(radius=r * cell, color=C_ACCENT, stroke_width=3)
            ring.move_to(kgrid.get_center())
            if shown is None:
                self.play(FadeIn(g), FadeIn(lab), Create(ring))
            else:
                self.play(FadeOut(shown[0]), FadeOut(shown[1]), FadeIn(g), FadeIn(lab),
                          Transform(shown[2], ring))
                ring = shown[2]
                g_old = None
            shown = (g, lab, ring)
            self.wait(0.8)
        StepCaption(self, "More k-space coverage means lower reconstruction error.")
        self.wait(1.5)


if __name__ == "__main__" and "--selftest" in sys.argv:
    # full k-space reproduces the image exactly
    full, _ = recon(K, 10 ** 6)
    assert np.allclose(full, IMG, atol=1e-9)
    # error decreases as more k-space is included
    assert ERRS[0] > ERRS[1] > ERRS[2]
    # k-space center equals the sum of the image
    assert np.isclose(K[16, 16].real, IMG.sum())
    print("ok")

The Manim scene code that draws this lesson's animation in the Signals AI app (Python, Manim Community).

ccBYNC© 2026 SignalsLab. Lesson text shared as is under CC BY-NC 4.0.