Week 02 · Filtering, gradients, and edges

Measure how smoothing changes the signal-to-noise ratio of an edge.

← Week 1 · Subject contents · Week 3 →

Measure how smoothing changes the signal-to-noise ratio of an edge.

Work through the problem

A local finite difference I(x+1)−I(x) is large across a sharp transition. Independent pixel noise with variance σ² contributes variance 2σ² to that difference. Smoothing suppresses random fluctuations but spreads a transition over more pixels.

This lab repeats a weak vertical step across rows. Average neighbouring rows before taking the horizontal difference. Since the edge is aligned across those rows, its mean strength stays about the same. The same average can blur an edge that changes position from row to row.

A weak step with and without smoothing. Panels from left to right: Clean, Noisy, Row average.

A weak step with and without smoothing.

Run the Python lab

import numpy as np
from scipy.ndimage import uniform_filter1d
rng = np.random.default_rng(28)
clean = np.zeros((36,36))
clean[:,18:] = .35
noisy = clean + rng.normal(0,.16,clean.shape)
blurred = uniform_filter1d(noisy,size=5,axis=0)
raw, smooth = np.diff(noisy,axis=1),np.diff(blurred,axis=1)
for name, gradient in [("Raw",raw),("Smoothed",smooth)]:
    snr = gradient[:,17].mean()/gradient[:,:15].std()
    print(name,"edge SNR",round(snr,2))
assert smooth[:,:15].std() < raw[:,:15].std()

Output from the lab

Raw edge SNR 1.53
Smoothed edge SNR 3.37

Practice

  1. What happens if you average across the horizontal direction too?

Check your reasoning

  1. It can reduce noise further but also smear the edge across columns and reduce its peak gradient.

← Week 1 · Subject contents · Week 3 →

Further reading · Szeliski · Computer Vision: Algorithms and Applications