CV Lab 08 · Module 2 — Filtering & Noise

Bilateral Filteringedge-preserving

Gaussian smooths everything — noise and edges alike. Bilateral is smarter: it only trusts a neighbour if that neighbour is close in space AND similar in colour. Result — flat regions get smoothed to porcelain while edges stay razor sharp. This is the magic behind portrait beautification, cartoon filters, and HDR tone mapping.

noisy Gaussian Bilateral
One image, two profiles Feed both filters the same noisy step-edge signal. Gaussian smears everything (including the edge). Bilateral smooths the flat noise but leaves the edge razor-sharp. That's the whole invention.
Ready.
σ spatial
2.5
σ range
40
Kernel size
7 × 7

Hover on the image — a live "neighbour trust map" appears on the right, showing which nearby pixels bilateral is willing to average and which it refuses. On a smooth region the map is a bright blob. On an edge, it literally gets cut in half.

Weight = spatial × range
w = exp(−d² / 2σs²) · exp(−ΔI² / 2σr²) = final trust
Spatial (distance) Range (intensity diff) Product

Why "close + similar" is such a big deal

The two-question filter

For every neighbour, bilateral asks two things: "How far are you?" and "How different in colour are you?" Only if both answers are small does the neighbour get to vote. This one extra question turns a mediocre smoother into an edge-preserving one.

σ spatial vs σ range

σ spatial controls how far the influence spreads (like a normal Gaussian). σ range controls how much colour difference is tolerated. Small σ range = ultra-edge-preserving (great for portraits). Large σ range → filter degenerates back into a regular Gaussian.

Why it's slow (and worth it)

Bilateral can't be separated into 1D passes like Gaussian, because each pixel's weight depends on this specific neighbourhood's colours. That makes it 10× slower — but modern phones do it in real time to make selfies look smoother without losing eye and lip crispness.

Predict, then verify

You're smoothing a portrait for a beauty filter. You want skin porcelain-smooth but eyes, eyebrows, and lips razor sharp. Which setting makes bilateral behave most like this?