Joshu Leonardy
周 · 波 · 数 · 領 · 域

Frequency Domain Lab

Any image can be built by adding up waves: stripes of different spacing, direction and strength. The Fourier transform tells you how much of each wave an image contains. Laid out as a picture, that list is called the spectrum. This lab starts by building images out of waves by hand. It then reads a real photograph's spectrum point by point, and finishes by filtering images by editing the spectrum directly.

— 01 —
波 · の · 和

Every image is a sum of waves

Gonzalez & Woods, 4th ed. §4.5 Extensions to Functions of Two Variables; §4.6: The 2-D DFT and IDFT (p. 240)  ·  Burger & Burge — The discrete Fourier transform in 2D

The dark square on the right is an empty spectrum. Each point in it stands for one wave. Its distance from the centre sets how many stripes fit across the image, and its direction sets which way the stripes run. Click anywhere to add that wave to the image, and click the same point again to remove it. Hover to preview a wave before you add it.

f(x, y) = 1 / MN M−1Σu = 0N−1Σv = 0F(u, v) e j2π(ux/M + vy/N)

This is the inverse DFT, and it says the same thing as the picture: f is a weighted sum of waves, with weights F(u, v). A wave at (u, v) completes u cycles across the image and v cycles down it. Its crests are √(u² + v²) cycles per image apart, so the period is 256 / √(u² + v²) pixels. Each wave you add lights up two points, mirrored through the centre. A real image always has this symmetry, because a cosine is the sum of two complex exponentials, one at (u, v) and one at (−u, −v).

Start from
Waves in the image · click one to remove it
Image f(x, y)
Spectrum |F(u, v)|, centred · click to add
Under the pointer
Hover over the spectrum.
— 02 —
振 · 幅 · と · 位 · 相

Reading a real spectrum

Gonzalez & Woods, 4th ed. §4.6: Fourier Spectrum and Phase Angle (p. 249)  ·  Burger & Burge — The discrete Fourier transform in 2D: visualizing spectra

A photograph contains every wave at once, and the spectrum shows how much of each. Most of the energy sits near the centre, in slow waves that set overall brightness and shading. Far from the centre are the fast waves that make up fine detail and sharp edges. Straight edges in the image produce bright streaks through the centre, running perpendicular to the edge. Hover over the spectrum to see which wave any point stands for.

F(u, v) = M−1Σx = 0N−1Σy = 0f(x, y) e −j2π(ux/M + vy/N)  =  |F| e jφ
Hover over the spectrum to read one coefficient.

Each F(u, v) is a complex number. Its magnitude |F| says how strong that wave is, and its phase φ says where the wave's crests sit. The magnitudes span many orders of magnitude, since the centre value alone is the sum of every pixel. That is why spectra are shown as log(1 + |F|). Switch to Linear to see why. Images are cropped and resized to 256 × 256 here, so the DFT is exact and fast.

Show
Centring
Image
Spectrum
The wave at this point
Hover over the spectrum.

Magnitude or phase: which one holds the picture?

Take the magnitudes from one image and the phases from another, then invert. Before you look, guess which image you will recognise.

Second image
A
B
|A| with phase of B
|B| with phase of A
The phase wins. Magnitude records how much of each wave is present, but phase records where each wave's crests line up, and edges and shapes are exactly the places where many waves line up at once. This is why filters in the next section change the magnitude and leave the phase alone. Such filters are called zero-phase filters.
— 03 —
低 · 域 · と · 高 · 域

Filtering: multiply, then invert

Gonzalez & Woods, 4th ed. §4.7 The Basics of Filtering in the Frequency Domain; §4.8 Lowpass (pp. 272–283); §4.9 Highpass (p. 284 on)  ·  Burger & Burge — The discrete Fourier transform: applications

Frequency-domain filtering takes three steps: transform the image, multiply every coefficient by a filter value H(u, v) between 0 and 1, and transform back. A lowpass filter keeps the centre of the spectrum and removes fine detail. A highpass filter does the opposite. The filter's shape matters as much as its cutoff, and the spatial kernel on the right shows why.

g(x, y) = 𝔉−1[ H(u, v) F(u, v) ]   ⇔   g = h ★ f

The convolution theorem is the bridge back to lab 03. Multiplying by H in the frequency domain is exactly the same as convolving with a kernel h in the spatial domain, where h is the inverse transform of H. A sharp cutoff in H gives an h with ripples that repeat outwards. Convolving with those ripples copies each edge a few times, faintly, and those copies are the ringing. A Gaussian H has a Gaussian h, which has no ripples and so causes no ringing.

Pass
Shape
Cutoff D₀
Order n
Filter H(u, v)
Filtered spectrum H·F
Spatial kernel h(x, y), centre 49 × 49
Kernel cross-section h(x, 0) · negative lobes cause ringing
Filter cross-section H(u, 0)
Row profile
— 04 —
周 · 期 · 雑 · 音

Periodic noise and notch filters

Gonzalez & Woods, 4th ed. §4.10: Notch Filters (p. 299), eq. 4-151; §5.4 Periodic Noise Reduction Using Frequency Domain Filtering  ·  Burger & Burge — The discrete Fourier transform: applications

Electrical interference, scanned halftone prints and some cameras add a regular pattern on top of the image. In the image this pattern is spread across every pixel. In the spectrum it is concentrated into a few bright spikes, because it is made of only a few waves. Click on a spike to place a notch (a small hole in the filter) there, and click the notch again to remove it. Your goal is to remove the pattern and nothing else.

HNR(u, v) = QΠk = 1[ 1 − e −Dk² / 2r² ] [ 1 − e −D−k² / 2r² ]

Dk is the distance from notch k. Each factor is a Gaussian hole of radius r, equal to 0 at the notch centre and close to 1 elsewhere. Notches always come in mirrored pairs, for the same symmetry reason as in section 01: removing only one of the pair would leave a filtered image that is no longer real-valued.

Interference
Notch radius r
Notches
Noisy spectrum · click spikes to notch them
Notch filter HNR
What was removed (noisy − result)