How it works

This page explains the calculations K-Space Paint performs behind the scenes, using the same definitions as the actual program.

K-Space Paint is a teaching tool for learning how the Fourier transform relates images to k-space. It does not reproduce how an MRI scanner acquires signals or reconstructs images, and it must not be used for medical decisions (see “Differences from real MRI” below).

1. Grid and coordinates

Both image space and k-space are N×N grids (N=256).

2. Fourier transform

Drawing an image (forward transform)

The app computes the 2D discrete Fourier transform of the image you draw, f(x,y) (white = 1, black = 0).

F(u,v)= ∑x=0N−1 ∑y=0N−1 f(x,y) e−i2π(ux+vy)/N

Drawing in k-space (inverse transform)

The app computes the 2D inverse discrete Fourier transform of the k-space you draw, F(u,v) (complex-valued).

f(x,y)= ∑u=−128127 ∑v=−128127 F(u,v) e+i2π(ux+vy)/N

The normalization factor 1/N2 is omitted. Because the display divides by the maximum value, the result looks the same on screen with or without it. The calculation uses a fast Fourier transform (radix-2 FFT), but the results match the definitions above (see “6. Verification”).

Because both transforms are discrete, the image wraps around periodically: the top and bottom edges, and the left and right edges, are treated as neighbors.

3. Display processing

Raw results are hard to see, so the following processing is applied before converting them to brightness values from 0 to 1. What you see is a processed version of the result, so brightness is not proportional to the magnitude of the values.

What is shownDisplayed value
Reconstructed image I=(|f(x,y)|max|f|)0.85
The absolute value (magnitude) is divided by its maximum and brightened slightly (gamma 0.85).
k-space (result of the Fourier transform, or k-space taken from an image) L=ln(1+1000⋅|F|/max|F|)ln(1001)
The values are compressed logarithmically so that the center (DC component) does not drown out everything else (the views labeled “log scale”). Phase is not displayed.
k-space you drew yourself |F(u,v)| is shown as is (0 to 1).
Tiny points of 1–4 cells in k-space A single cell of the 256×256 grid is only a few pixels on screen and easy to miss. So for any group of nonzero cells connected horizontally, vertically or diagonally that has 4 cells or fewer and no other points or lines within 2 cells, each cell is drawn as a 5×5 block in the display only (e.g. the “Center point”, “Symmetric pair” and “Random” presets). The data used in the calculation is unchanged, and the reconstructed image is not affected.

Example: why the stripes look finer with “Symmetric pair”

The “Symmetric pair” preset puts the value 1 at (u,v)=(10,4) and (−10,−4). This gives f=2cos(2π(10x+4y)/N). Since the screen shows the absolute value |f|, the negative parts are also bright, so you see twice as many bright stripes as there are cosine periods.

4. Brush

Each brush dab adds a smooth Gaussian-shaped value centered on your finger (or mouse). The amount added to a cell at offset (dx,dy) from the center is:

Δ=s⋅ exp(−dx2+dy22r2)
Where and which toolHow the value changes
Image space, pen / eraserf←min(1,max(0,f+Δ))
k-space, penΔ is added to the real part. If the magnitude exceeds 1, it is clamped to 1 while keeping the phase.
k-space, eraserF←F⋅max(0,|F|+Δ)|F|
Only the magnitude is reduced; the phase is kept.

Symmetry mode (Hermitian symmetry)

When “Symmetry” is on, whatever you draw at (u,v) is also drawn at the point mirrored through the center, (−u,−v). k-space drawn in symmetry mode (and k-space taken from an image) satisfies

F(−u,−v)=F(u,v)‾

(the complex conjugate), so the inverse transform f(x,y) is real-valued. This gives a natural look, closer to an image of a real object. Note that the column u=−128 and the row v=−128 (the left and top edges of the screen) pair with themselves, because their counterparts would lie outside the grid.

5. Loading images

6. Verification

The program's FFT results were checked against values computed by directly summing the definitions above (October 3, 2026).

7. Differences from real MRI

The “k-space” in K-Space Paint is simply the 2D discrete Fourier transform of the image. Real MRI differs in the following ways.

Last updated: October 3, 2026