The idea: scale the waves, not the pixels

Any image can be written as a sum of 2-D waves of different speeds and directions. The 2-D discrete Fourier transform (DFT) finds how much of each wave is in the image: that list is the spectrum F. To filter, multiply every value of F by a number H(u, v) and transform back. A low-pass filter keeps the slow waves and blurs; a high-pass filter keeps the fast waves and leaves the edges; a notch filter removes a few chosen waves.

Five small images in a row: the 16 by 16 image f; a DFT arrow to the log-scale spectrum |F| with DC in the middle; times the ideal low-pass filter H, a white disc of radius 3; equals G, where 29 frequencies pass and 95.4 % of the energy is left; an IDFT arrow to the blurred output g with range 32.0 to 215.5.
Three steps: transform, multiply by H, transform back. Every frequency is scaled on its own.

The page uses a 16×16 image: an 8×8 square of brightness 200 on a background of 60. That is small enough to compute every one of the 256 DFT values exactly in the browser. The five panels are the image f, the spectrum |F|, the filter H, the product G = F·H and the output g. Below them, row 8 of f and g is drawn as a profile, so you can read the actual numbers.

The 2-D DFT is rows, then columns

For an M×N image the DFT is F(k, l) = Σr Σc f(r, c) · e−2πi(kr/M + lc/N). The double sum splits: first do a 1-D DFT of every row, then a 1-D DFT of every column of that result. This is why the 2-D transform costs about 2N times a 1-D one, and why any 1-D FFT can be reused for images (see Fourier Series and the FFT for the 1-D DFT and the FFT itself).

F(0, 0) is the plain sum of all pixels, the DC term: 256 × 95 = 24 320 for the square. The values come out with (0, 0) at the top-left corner. Swapping the four quadrants (fftshift) moves it to the centre, so the distance D(u, v) = √(u² + v²) from the centre is the frequency: near the centre the waves change slowly, at the edges they change every pixel. Spectra are shown on a log scale, log(1 + |F|), because the DC is many times bigger than the rest (Demo 1: the spectrum of a square).

whatvalue for the square
DC, F(0, 0)24 320 (71.1 % of all energy)
|F(±1, 0)|, |F(±3, 0)|, |F(±5, 0)|5740.9, 2015.9, 1347.0
|F(±2, 0)|, |F(±4, 0)|, |F(±6, 0)|0: an 8-wide box in 16 pixels has no even harmonics
non-zero values81 of 256: u and v each 0 or odd, a 9×9 lattice

Energy is the sum of |F|². By Parseval's theorem it equals 256 times the sum of the squared pixels, so "energy kept" after filtering is simply Σ|G|² / Σ|F|².

Low-pass: ideal vs Gaussian

The ideal low-pass filter keeps every frequency with D ≤ D0 and drops the rest: H is a sharp disc. The Gaussian low-pass H = exp(−D² / (2D0²)) has no edge: 1 at the centre, 0.61 at D = D0, fading out.

Left: a cross-section of the two filters along u, the ideal one a box of height 1 from minus 3 to 3, the Gaussian a bell with value 0.61 at plus and minus 3. Right: row 8 of the output. The ideal filter's profile overshoots to 213 and undershoots to 39 near the square's edges; the Gaussian profile rises smoothly from 60 to 200 without crossing those lines.
A sharp cut in frequency gives ripples in space; a smooth cut gives a smooth edge.

Both blur the square, but they differ at its edges. With D0 = 3 (Demo 2: ideal low-pass, D0 = 3: ringing, Demo 3: Gaussian low-pass, D0 = 3: no ringing):

D0 = 3ideal low-passGaussian low-pass
frequencies passed29 of 256all, weighted
energy kept95.4 %91.8 %
output range (input 60 … 200)32.0 … 215.559.97 … 200.05
overshoot / undershoot15.5 / 28.0both under 0.1

This ringing is the same overshoot as the Gibbs effect of a Fourier series: cutting the series off sharply leaves ripples next to every jump. The inverse DFT of a sharp disc is a sinc-like pattern with negative side lobes, and multiplying by H is the same as convolving the image with that pattern. The Gaussian's inverse is again (nearly) a Gaussian with no real negative lobes, so it only averages: on this grid the overshoot is under 0.1. It keeps less energy at the same D0, yet looks cleaner. Try D0 = 2, 4 and 6 with the D0 menu: the ideal filter rings at every size.

High-pass: edges

A high-pass filter is 1 − low-pass. It removes the DC, so the output has mean 0 and is drawn with grey = 0, dark = negative, light = positive. What is left are the places where the image changes: the border of the square. On row 8 with D0 = 3 the Gaussian high-pass gives −37.3 just outside the edge, +37.3 just inside, and 0.0 in the flat parts (Demo 5: Gaussian high-pass, D0 = 3: clean edges). The ideal high-pass finds the edge too (−37.4 | +45.6) but rings: the flat background at column 0 reads 20.3 instead of 0 (Demo 4: ideal high-pass, D0 = 3). Edge detectors usually work in space with small kernels instead; see Canny Edge Detection.

Notch: removing a repeating pattern

A pattern that repeats across the whole image, such as scan lines or mains-hum stripes, is one wave, so in the spectrum it is just a pair of bright dots. The second image adds 40·cos(πc/2) to every row: a wave that repeats every 4 columns, so it sits at (u, v) = (±4, 0) with |F| = 5120 each. A notch filter sets H = 0 on those two dots and 1 everywhere else. The square happens to have exactly 0 at (±4, 0), so the output is the clean square again, to within 1e-13 (Demo 6: a notch filter removes the stripes).

A low-pass with D0 = 3 removes the stripes too, since D = 4 is outside the circle, but it blurs and rings the square exactly as in Demo 2: the output is the same to 1e-13 (Demo 7: low-pass on the stripes blurs the square too). The notch keeps 94.1 % of the energy, the low-pass 89.7 %.

The convolution theorem

Multiplying spectra is the same as convolving images: if g = f ⊛ h (circular convolution), then G = F · H with H the DFT of the kernel h padded to the image size. The page checks it on a 3×3 box blur, nine weights of 1/9 (Demo 8: convolution = multiplication (3×3 box)). The kernel is padded to 16×16 with its centre at pixel (0, 0), so its cells wrap around the corners. Its DFT is real, H(u, v) = (1 + 2cos(2πu/16)) · (1 + 2cos(2πv/16)) / 9: 1 at the centre, −1/3 at the far edges. The two ways agree on every pixel, for example pixel (4, 4) = (4·200 + 5·60) / 9 = 122.22, with a largest difference of about 1e-13 (rounding). For the sliding-window view of the same operation see Convolution.

in spacein frequency
work for one N×N image, k×k kernelN² · k² multiply-adds3 FFTs (about N² log N each) + N² products
wins whenthe kernel is small (3×3, 5×5)the kernel is large, or H is designed directly
edges of the imagepad as you likewraps around unless the image is padded first

See also JPEG and the DCT, which drops high frequencies of 8×8 blocks to save space, Sampling and Aliasing for why the highest frequency is half the sample rate, and Histogram Equalization for filters that look at one pixel only.

See also FIR and IIR filters, which low-pass filters a 1-D signal one sample at a time with a windowed sinc, a moving average and a feedback filter.

What the page leaves out

Real images are hundreds of pixels wide and use the FFT, not direct sums. To avoid the wrap-around of circular convolution, images are padded to twice their size before filtering, and often multiplied by (−1)r+c instead of shifting the spectrum. The page also leaves out Butterworth filters (between ideal and Gaussian), band-pass and band-reject rings, homomorphic filtering, the phase of F (the page only shows |F|, but the phase holds most of the shape), and colour images.

On the mind map

Open the Machine Learning mind mapMachine LearningLearning setup: what feedback, how to scoreLearning setupLinear models: weighted sum w·x + bLinear modelsOther classic models: trees, margins, neighboursOther classic modelsUnsupervised: find structure without labelsUnsupervisedTraining: loss, gradient, small stepTrainingNeural networks: layers of σ(W·a + b)Neural networksArchitectures: how layers share informationArchitecturesLanguage models: predict the next tokenLanguage modelsLLM speed and tuning: cheaper to run, safer to useLLM speed and tuningRetrieval and agents: give the model data and toolsRetrieval and agentsConvolutionConvolutionslide a small kernel over the imageCNN layer by layerCNN layer by layerfc1 holds 78% of the weightsU-Net SegmentationU-Net SegmentationSkips concat channels; score masks with DiceCanny Edge DetectionCanny Edge DetectionBlur, gradient, thin, two thresholds, linkHarris CornersHarris CornersR = det − k·trace² large: cornerHistogram EqualizationHistogram Equalizationrunning sum of counts = new levelsFrequency-domain filteringSharp cut in H rings; Gaussian does notOtsu ThresholdingOtsu ThresholdingMax between-class variance picks tHough TransformHough TransformCollinear pixels' curves cross in one cellErosion and DilationErosion and DilationErode = B fits, dilate = B hitsCNN vs TransformerCNN vs Transformerlocal field vs attention to allRNN, LSTM, GRURNN, LSTM, GRUhidden state; gates fight vanishingSelf-attentionSelf-attentionsoftmax(QKᵀ/√d_k) weights the VDiffusion modelDiffusion modellearn to predict the added noiseVAE vs GANVAE vs GANELBO loss vs generator-discriminator gameAutoencoderAutoencoder2-number bottleneck; rebuild inputContrastive learning, CLIPContrastive learning, CLIPmatch pairs in one space, InfoNCE lossResidual connectionsResidual connectionsx + F(x) lets gradients skip layersOpen the Machine Learning mind mapMachine Learninghow layers share informationArchitecturesConvolutionConvolutionslide a small kernel over the imageCNN layer by layerCNN layer by layerfc1 holds 78% of the weightsU-Net SegmentationU-Net SegmentationSkips concat channels; score masks with DiceCanny Edge DetectionCanny Edge DetectionBlur, gradient, thin, two thresholds, linkHarris CornersHarris CornersR = det − k·trace² large: cornerHistogram EqualizationHistogram Equalizationrunning sum of counts = new levelsFrequency-domain filteringSharp cut in H rings; Gaussian does notOtsu ThresholdingOtsu ThresholdingMax between-class variance picks tHough TransformHough TransformCollinear pixels' curves cross in one cellErosion and DilationErosion and DilationErode = B fits, dilate = B hitsCNN vs TransformerCNN vs Transformerlocal field vs attention to allRNN, LSTM, GRURNN, LSTM, GRUhidden state; gates fight vanishingSelf-attentionSelf-attentionsoftmax(QKᵀ/√d_k) weights the VDiffusion modelDiffusion modellearn to predict the added noiseVAE vs GANVAE vs GANELBO loss vs generator-discriminator gameAutoencoderAutoencoder2-number bottleneck; rebuild inputContrastive learning, CLIPContrastive learning, CLIPmatch pairs in one space, InfoNCE lossResidual connectionsResidual connectionsx + F(x) lets gradients skip layers
This page on the Machine Learning mind map · 88 pages in 10 branches · open it to see the whole map and test yourself in recall mode.