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.
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.
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).
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.
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.
Take the magnitudes from one image and the phases from another, then invert. Before you look, guess which image you will recognise.
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.
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.
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.
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.