C10 · Change and measure
Nonlinear filters
Choosing by rank, adapting weights or seeking similar patches are different ways to separate noise from structure.
Background if needed
Theory
Order first
Min/max choose extremes; median chooses the middle ordered sample. Percentiles generalize rank; trimmed means discard extremes before averaging. Impulses and thin detail respond differently.
Select an isolated bright point in a dark area and compare median with mean. Now select the thin line: it can disappear too, since a rare value is not necessarily noise. The calculation orders those same neighbours; for 9 values the median is the fifth.
Middle in order is not the mean
Compare median and mean on impulses, then enlarge the window. Check the thin line, not just background smoothness.
Exact values are in the point inspector
Grayscale -0.5…1.5: black to white.
- Order values; weights are shown at their original positions
Exact values are in the point inspector
Grayscale -0.5…1.5: black to white.
Inspect the selected point
What the plot shows
Each curve point is a pixel value on the marked horizontal line. Select another image row to move the graph. Compare edge width and preservation of detail.
- Input
- Output
- Clean reference
Median resists isolated outliers but cannot know whether a thin line is useful detail.
Parameters and details
One noisy scene contains an edge, a thin line and stripes. The median selects the middle ordered sample, not the arithmetic mean. The trimmed mean removes two values at each end. Borders repeat; the source array is neither sorted nor modified.
Select an image point. Arrows move it; Home and End reach row edges. Viewing does not change the calculation.
Changing the example requires JavaScript and Canvas. Computed images remain available above.
Two weight factors
Bilateral weight is coordinate proximity times similarity to the centre. Influence across a strong edge falls. Normalization preserves constant levels, but data-dependent weights make the filter nonlinear.
Select a reference point just left of the edge on the right image, then a candidate across the edge on the left image. Read the two factors and their product. Change only similarity tolerance: spatial proximity stays unchanged while cross-edge influence changes. Too little tolerance retains some noise too.
Close in position and value
Select an edge point. Lower tolerance: cross-edge influence falls, but excessive strictness preserves noise.
Exact values are in the point inspector
Grayscale -0.5…1.5: black to white.
- Selected candidate: proximity × similarity
Exact values are in the point inspector
Grayscale -0.5…1.5: black to white.
Inspect the selected point
What the plot shows
Each curve point is a pixel value on the marked horizontal line. Select another image row to move the graph. Compare edge width and preservation of detail.
- Input
- Output
- Clean reference
Weights depend on data: the operation is nonlinear despite resembling a weighted mean.
Parameters and details
A 5 × 5 window multiplies spatial Gaussian weights by similarity to the centre, then normalizes. Large range tolerance approaches ordinary smoothing; a small one can preserve noise or false edges.
Select an image point. Arrows move it; Home and End reach row edges. Viewing does not change the calculation.
Changing the example requires JavaScript and Canvas. Computed images remain available above.
Pattern similarity
Non-Local Means compares patches around points, not just one code. Similar structures receive larger weights. Search and patch size determine similarity meaning and cost; both are bounded here for transparent live computation.
Choose a reference patch on the right and a candidate on the left. Nine pixel pairs in the outlined windows are compared. A low mean squared difference gives a high similarity weight. Similar centre pixels can have different surrounding patterns; NLM then distinguishes them whereas centre-only comparison cannot.
Compare patches
Select a stripe. Candidates compare 3 × 3 patches in a 7 × 7 search. Change tolerance and inspect contributions.
Exact values are in the point inspector
Grayscale -0.5…1.5: black to white.
- Selected candidate: proximity × similarity
Exact values are in the point inspector
Grayscale -0.5…1.5: black to white.
Inspect the selected point
What the plot shows
Each curve point is a pixel value on the marked horizontal line. Select another image row to move the graph. Compare edge width and preservation of detail.
- Input
- Output
- Clean reference
Structure is more informative than one code, but noise can create false matches. Cost grows with search and patch size.
Parameters and details
Bounded NLM: 7 × 7 search, 3 × 3 patches, mean squared difference and an extra spatial weight. The centre patch is included with weight 1. This is a real small-scene calculation, not a full fast photographic NLM/BM3D implementation.
Select an image point. Arrows move it; Home and End reach row edges. Viewing does not change the calculation.
Changing the example requires JavaScript and Canvas. Computed images remain available above.
Reference: other ways to use structure
Reference and further methods
Adaptive median selects a window size from contamination tests; local Wiener uses mean, variance and a noise estimate. Guided filtering builds a local model from a guide image whose irrelevant edges can leak into the result. BM3D groups similar patches and filters the transformed group. These are separate methods, not modes of the calculations shown above. Wavelets and total variation have their own linked chapters.
Practice
Test the idea under another condition. Follow the task above the images; point inspection helps explain the result. This exploration is not scored.
An edge or leftover noise?
This new scene has a diagonal edge and a thin horizontal line. The initial large tolerance mixes both sides. Lower it to preserve the edge, then find a value so small that noise remains. Check both flat background and the line against the reference: a good edge setting need not preserve every detail.
Exact values are in the point inspector
Grayscale -0.5…1.5: black to white.
- Selected candidate: proximity × similarity
Exact values are in the point inspector
Grayscale -0.5…1.5: black to white.
Inspect the selected point
What the plot shows
Each curve point is a pixel value on the marked horizontal line. Select another image row to move the graph. Compare edge width and preservation of detail.
- Input
- Output
- Clean reference
Weights depend on data: the operation is nonlinear despite resembling a weighted mean.
Parameters and details
A 5 × 5 window multiplies spatial Gaussian weights by similarity to the centre, then normalizes. Large range tolerance approaches ordinary smoothing; a small one can preserve noise or false edges.
Select an image point. Arrows move it; Home and End reach row edges. Viewing does not change the calculation.
Changing the example requires JavaScript and Canvas. Computed images remain available above.
Games
Test your explanation
Question 1 of 5
Median filtering removed a thin line along with impulses. Was it guaranteed to preserve the line?
Exact values are in the point inspector
Grayscale -0.5…1.5: black to white.
Exact values are in the point inspector
Grayscale -0.5…1.5: black to white.
Exact values are in the point inspector
Grayscale -0.5…1.5: black to white.
Exact values are in the point inspector
Grayscale -0.5…1.5: black to white.
Choose one answer. It is checked immediately.
Limitations and references
Limits of this example
Live rank/mean, 5 × 5 bilateral filtering and NLM with 7 × 7 search and 3 × 3 patches. Guided, adaptive median, local Wiener and BM3D are explained, not claimed executed.