CS Fundamentals Trainer · Guides

Filtering in space and in frequency: one operation, two views

Convolution as multiplication of spectra and the impulse as a constant. The sum of a kernel is its gain at zero frequency, highpass, bandreject and bandpass kernels built from one lowpass, why a wide Gaussian has a narrow spectrum, aliasing and filtering before shrinking, and when to compute in the frequency domain.

8 min read

Every spatial filter has a second description that is often easier to reason about: what it does to the frequencies in the image. Edges, noise and fine texture live in the high frequencies; walls, skies and gentle shading live in the low ones. Blurring removes the former, sharpening boosts them, and "lowpass", "highpass" and "bandpass" are names for what a filter keeps. This guide connects the two views, so that you can predict the effect of a kernel from its shape and design one from the effect you want.

1. The two facts that connect everything

  1. Convolution in the spatial domain is multiplication in the frequency domain (and the other way round). Filtering an image with a kernel w means multiplying the image's spectrum by the spectrum of w.
  2. An impulse of strength A in the spatial domain is a constant A in the frequency domain (and the other way round). A kernel with a single 1 and zeros elsewhere, the unit impulse, has a flat spectrum equal to 1 and passes everything unchanged.

Everything else in this guide follows from these two, together with the fact that a picture can be written as a sum of sinusoids of different frequencies and amplitudes. Slowly varying regions need low-frequency sinusoids, and sharp transitions need high-frequency ones.

2. Frequency as a picture

A zone plate is a test image of concentric rings that get narrower away from the centre, so its local frequency increases with the distance from the centre. Filter it and the result shows the filter's frequency behaviour as a picture:

A zone plate is a good first test for any kernel you write. If the output pattern is square instead of round, the kernel is not isotropic (a separable kernel built from a 1-D profile gives a squarish pattern, while rotating the same 1-D profile about the centre gives a round one).

3. The sum of the coefficients is the gain at zero frequency

The "DC" component (frequency zero) is the average level of the image. A kernel multiplies it by the sum of its coefficients.

KernelSumAt zero frequencyConsequence
Normalised box or Gaussian1gain 1flat regions keep their value
Laplacian, Sobel, highpass0gain 0flat regions give zero; the result has negative values and must be rescaled to display
Unsharp kernel (impulse + k × highpass)1gain 1brightness is kept while detail is boosted

This one fact explains why smoothing kernels are normalised, why derivative kernels sum to zero and why sharpening by adding a derivative image back to the original keeps the tonal range.

4. Building the four filter types from one lowpass filter

Let lp be a lowpass kernel and δ the unit impulse with the same centre. In the frequency domain "1 minus the lowpass" is a highpass, and 1 is the transform of δ, so:

FilterKernelWhy
Lowpasslpgiven
Highpassδ − lpthe spectrum 1 − H(u)
Bandrejectlp₁ + (δ − lp₂)a lowpass and a highpass with different cutoffs
Bandpassδ − bandrejectthe complement of the band that is rejected

A concrete case: the 3 × 3 box lowpass has 1/9 everywhere. Subtracting it from the impulse gives a highpass with 8/9 at the centre and −1/9 at the other eight places, which sums to zero. The unsharp mask f − blur(f) is exactly the output of that highpass, so unsharp masking is "add a highpass-filtered copy of the image to the original". Adding k times that highpass to the impulse gives the sharpening kernel; with k = 1 and the 3 × 3 box it is 17/9 in the centre and −1/9 elsewhere, which sums to 1.

5. The Gaussian pair

A Gaussian in space has a Gaussian spectrum, and the two widths are inversely related: a wide kernel (large σ) has a narrow spectrum. That is the reason a bigger σ blurs more, since it passes a narrower band of low frequencies. Three consequences follow:

6. Where sampling comes in

Sampling an image on a grid can represent frequencies only up to a limit set by the pixel spacing. Frequencies above it do not vanish; they fold back and show up as false lower frequencies (aliasing, moiré, jagged diagonals). The practical rules follow directly:

7. Space or frequency: which to compute in?

Both give the same result when done right, so the question is cost and convenience.

Two details need care when computing in the frequency domain:

8. Misconceptions

9. Self-check

Answers: both have gain 1; bandpass = δ − (lp₁ + (δ − lp₂)); σ = 2√2 ≈ 2.83, so a size of ⌈6σ⌉ = 17, which is already odd; because noise lives in the high frequencies too, a highpass keeps it.

Further reading

Practise this topic: Computer Vision

More guides