CV Lab 09 · Module 2 — Filtering & Noise

DenoisingNon-Local Means

Every filter so far only trusted nearby pixels. Non-Local Means throws that rule away — it searches the whole neighbourhood for patches that look like the one you're denoising, wherever they are, and averages those. Repetition anywhere in the image becomes ammunition against noise.

far apart, same texture → still averaged
Search everywhere, not just nearby Two patches with matching texture, on opposite sides of the image. A local filter would never connect them. Non-Local Means finds this match and lets it vote — the more twins it finds, the more confidently it can cancel out noise without blurring texture.
Ready.
Noise level
σ 20
Patch size
5×5
Search window
11×11
Filter strength h
20

Click anywhere on the image to see which patches NLM found as "twins" for that spot — glowing lines will point to every match, with brighter = higher trust. A bar chart below ranks them.

Patch weight by rank (amber = the pixel itself)
Higher bars = more similar patches = more say in the final average

Why "search everywhere" actually works

Noise is random, texture repeats

Noise at any pixel is an independent random number — no relationship to noise anywhere else. But real image texture (brick, fabric, skin, grass) repeats constantly. If you find 20 patches that share the same underlying texture, their noise mostly cancels when averaged, while the shared texture survives.

Patch distance, not pixel distance

NLM compares whole small patches (e.g. 5×5), not single pixels — a single noisy pixel is unreliable, but a 25-pixel patch has enough signal to say "this looks like that" with confidence. The comparison itself is done with a Gaussian-weighted sum of squared differences between the two patches.

The cost of being thorough

Checking every candidate patch in a search window is far more expensive than Gaussian or bilateral's local-only search — that's why real implementations (including OpenCV's fastNlMeansDenoising) use optimised C++ and still run slower than simpler filters. Worth it when quality matters more than speed: astrophotography, forensics, old-photo restoration.

Predict, then verify

You have a noisy photo of a brick wall (lots of repeating texture) and a noisy photo of a single person's face on a plain background (very little repetition). Non-Local Means will help more on which one?