mri · part two · the encoding
Part one ended on a problem. The sensor is one coil of wire; it integrates the entire body into a single time-varying voltage and has no spatial resolution whatsoever. An MRI scanner is a one-pixel camera. Every pixel you have ever seen in an MR image was manufactured by making the precession frequency depend on where you are.
Switch on a gradient — a field that varies linearly across the bore — and a spin at position x precesses at γ̄·G·x. Now the single voltage the coil induces is a sum of every location's contribution, each at its own frequency:
Which is to say: the voltage at time t is one sample of the object's Fourier transform, at whatever spatial frequency the gradients have driven you to. The gradients are a steering wheel, k is where the car is, and the readout is a drive through frequency space. Twieg and Ljunggren, independently in 1983, are the people who put it that way — and once you do, reconstruction is an inverse Fourier transform and nothing else. No model, no prior, no network. Sixty lines of Cooley–Tukey.
Below is a real acquisition: a phantom whose k-space is evaluated in closed form (so that undersampling aliases for the same reason a real scanner's does, rather than because a grid got reused), sampled along the trajectory you pick, then inverse-transformed. Press acquire and watch k-space fill in the order the scanner really fills it.
k-space is not a picture of anything. Its centre holds the low spatial frequencies — the bulk, the contrast, where the signal energy is — and its edges hold the high ones, which is to say the boundaries. Delete a part and see what that part was carrying. Paint on it directly, or take a preset.
The spacing between k-space samples, Δk, sets the field of view: FOV = 1/Δk. Skip every other line and you have doubled Δk, halved the FOV, and anything outside it does not vanish — it wraps, and lands on top of the anatomy that does fit. The furthest sample, k_max, sets the resolution: Δx = 1/2k_max. Both are the sampling theorem, not a failure of the reconstruction; the transform is doing exactly what it was asked.
Turn the undersample slider in §2 up and watch it happen. This is also the point where modern MRI earns its keep: parallel imaging — SENSE, GRAPPA — un-folds those copies using the fact that a coil array has several sensors with different spatial sensitivities. Which is the correction to part one: the sensor has no spatial resolution *individually*, and an array of them has a little, and that little is enough to fill in the lines you didn't acquire.
Here are two acquisitions that cover exactly the same k-space samples, of the same object, with the same off-resonance. The only difference is the order and the clock.
Spin-warp excites once per line, so its phase clock restarts sixty-four times and never accumulates. Single-shot EPI excites once for the entire image, so a spin that is off-resonance by Δf keeps gaining phase for the whole readout — and since the phase-encode axis is sampled only once per echo spacing, its bandwidth is thousands of times narrower than the readout's. The image slides along that axis by Δf · N · esp pixels. This is why EPI brains come out bent near the sinuses, and why fat lands somewhere its owner is not. At 3 T, fat precesses about 440 Hz from water; take the slider there and watch a whole head slide off its own outline.
The engine's test suite asserts this rather than illustrating it: it reconstructs, measures the image's centroid, and compares it with Δf · N · esp. Agreement is better than a tenth of a pixel across the range. And spin-warp's shift, for the same Δf, comes out at about four thousandths of a pixel.
Spin-warp waits a full repetition time — hundreds of milliseconds — for each of its lines, so a 128-line image takes about a minute. EPI takes all 128 lines after one excitation, in about 65 milliseconds: roughly a thousand times faster. That single fact is why functional MRI and diffusion imaging exist at all; you cannot watch a brain respond to a stimulus at one image a minute. And the price is everything in §5 — the distortion, the T₂* blur, the sensitivity to every imperfection in the field, all of which follow from the clock never restarting.
The phantom's k-space is evaluated from the closed-form Fourier transform of an
ellipse, checked against brute-force numerical integration; the FFT is checked against a
brute-force DFT; the field of view, the resolution, the aliasing and the EPI shift are each checked
against the formula the page quotes. cd sci/engine-rs && cargo test --release
— 29 known-answer tests — and cargo run --release --bin verify prints every result
beside its closed form.
engine: rust → wasm · no dependencies · 29 tests · part one · sci