2D Fourier Transform

Paint on an image spectrum, and rebuild a picture wave by wave

Fourier Analysis for Images

A photo is a signal too, just spread across two directions. Break it into striped wave patterns and you get the tool behind JPEG files and MRI scans.

Image Spectrum Lab

The middle panel is the image's 2D spectrum. Start with the stripes and turn the angle slider: the two bright dots swing round the centre with them. Then paint on the spectrum to erase frequencies and watch the rebuilt image change. Try erasing one dot of the stripes, the low-pass and high-pass buttons on the scene, or draw your own picture or upload a photo.

Image
Spectrum (paint to erase; centre = average brightness)
Rebuilt from the kept frequencies
100.0%
frequencies kept
100.00%
of the image's energy kept (Parseval)

256×256 pixels, so 65,536 complex frequencies, shown with the zero frequency in the middle and on a log scale (otherwise only the centre would be visible). The rebuilt image is one inverse 2D FFT of the masked spectrum, recomputed as you paint.

Go deeper:How the 2D FFT Works

The Fourier transform extends naturally to images. Every image is a sum of 2D sinusoidal stripe patterns at different frequencies and orientations, and the 2D FFT finds how much of each one is present. It is computed by running a 1D FFT along every row, then along every column of the result:

FFT2D(image) = FFTcols(FFTrows(image))

For the lab's 256×256 image that is 512 FFTs of length 256, done again in reverse every time you paint.

Go deeper:Reading the Spectrum
  • Centre: the zero frequency, the average brightness. Erase it and the picture loses its overall level.
  • Distance from centre: frequency. Near the middle are smooth regions and gradual shading; far out are sharp edges and fine texture.
  • Direction from centre: orientation. A point at angle θ is a stripe pattern whose crests run perpendicular to θ, which is why the dots rotate with the stripes. Strong horizontal edges in a picture make a bright vertical streak in its spectrum.
  • Brightness: strength, on a logarithmic scale. Without the log only the centre would be visible.

Every spectrum is symmetric through the centre, because a real image needs each frequency paired with its mirror image. That is why your brush paints two blobs.

Go deeper:Filtering an Image

Keeping only the centre is a low-pass filter: the image blurs, and around sharp edges you can see ripples, the 2D Gibbs effect of a hard-edged mask. Keeping only the outside is a high-pass filter: flat areas go grey and only the edges survive, which is the idea behind edge detection.

Multiplying the spectrum by a mask is the same as convolving the image with a kernel, so this is also how large blurs are done quickly:

  1. FFT the image
  2. FFT the filter kernel (padded to the same size)
  3. Multiply pointwise
  4. Inverse FFT

A regular pattern, like a screen-door texture or the halftone dots of a scanned magazine, shows up as isolated bright spots. Erase the spots and the pattern disappears while the picture stays. Hidden watermarks work in the opposite direction, tucking a faint signal into chosen frequencies.

Build an Image from Waves

Press build. The image is rebuilt from its own spectrum, adding the strongest wave first, then the next strongest, and so on. The first panel shows each new wave as it arrives. A few dozen waves already give the layout; the remaining thousands only add detail.

Wave #1
Sum of the first 1
Spectrum (lit = added, green = newest)
Original
0.00%
of the energy captured
100.0%
of the waves used
—
amplitude of the newest wave

Each wave is a frequency of the 128×128 spectrum together with its mirror image, which together make one real stripe pattern A·cos(2π(fₓx + fy y)/128 + φ). The wave panel shows its shape at full contrast; its true size is the amplitude above. The running sum is exactly the inverse FFT of the spectrum with only these waves switched on.

Go deeper:Why the Biggest Waves Come First

Natural images put most of their energy in a small number of low frequencies. Parseval's theorem says the energy of the image equals the energy of its spectrum, so the "energy captured" readout measures how close the sum is to the original. It typically passes 95% within the first hundred or so waves, out of more than eight thousand.

That imbalance is what compression exploits. Keep the large coefficients, drop or coarsely round the small ones, and the picture barely changes. Progressive JPEGs load in a similar order, coarse structure first, although JPEG works on small 8×8 blocks with the cosine transform rather than on the whole image: see the compressor in the Applications lesson.

The checkerboard is the exception. Its hard edges spread energy across many frequencies, so it needs far more waves before its corners turn sharp.

Spot a mistake or have an idea?

Search