MCS4304 · Topic 4Image noise & filtering
4
Image noise & filteringnoise models · mean / Gaussian / median · convolution · borders Practise · 16 Qs MCQ · 14

Exam card

  • Noise model: g(x,y) = f(x,y) + η(x,y). The goal is to estimate f from g without losing detail. The noise model decides the filter.
  • Gaussian (sensor) η ~ N(μ, σ²) · Poisson (shot) K ~ Poisson(λ), mean = var = λ · salt & pepper (transmission/storage, impulse) · speckle (ultrasound/radar, multiplicative g = f·η).
  • Noise causes false edges, broken segmentation, hidden features and lost small structures.
  • Spatial (on pixels, linear or non-linear) vs frequency domain. Mean (1/9)[1…1] blurs edges · Gaussian (1/16)[1 2 1; 2 4 2; 1 2 1] · median for salt & pepper, keeps edges, non-linear.
  • Which filter: Gaussian noise → Gaussian/mean · salt & pepper → median · Poisson → Gaussian/mean, then Wiener · speckle → Lee/Frost.
  • Convolution = cross-correlation with the kernel flipped. They are the same for symmetric kernels. CNN "convolution" (PyTorch) is really cross-correlation. Borders: zero · replicate · reflect · valid · truncated.

Key diagram

+ ηf (true)g = f + ηGaussianPoissonsalt&pepperspeckle

Key terms

g = f + ηsensor noiseGaussian N(μ, σ²)photon / shot noisePoisson(λ)salt & pepper / impulsespeckle (multiplicative)spatial vs frequency domainlinear vs non-linear filtermean filterGaussian filtermedian filterWiener filterLee / Frostkernelcross-correlationconvolution (flipped kernel)zero / replication / reflection paddingvalid filteringtruncated kernel

What this topic covers

  1. What is image noise?
  2. The four noise sources
  3. How noise hurts computer vision
  4. Noise filtering: spatial vs frequency domain
  5. Cross-correlation vs convolution
  6. Boundary handling

Deep summary

Everything here follows the Topic 4 slides; each part shows its slide numbers. Parts marked added are study aids we wrote, not lecture content.

1 · The noise model and the filtering problem Topic 4 · slides 3–5, 20–21

g(x,y) = f(x,y) + η(x,y)f(x,y)scene = 100ideal+η(x,y)noise = +7random=g(x,y)seen = 107observedfiltering: estimate f from g…without removing meaningful detail

An image is a digital record of a scene, and the recorded values can differ from the ideal ones because of sensor limitations, photon statistics, transmission errors and imaging process noise (slide 3).

Model (slide 4): the observed pixel is the original scene value plus the noise at that position, g(x,y) = f(x,y) + η(x,y). Worked: f = 100 and η = +7 give g = 107. We only ever see 107; the filtering problem is to estimate f from g without removing meaningful image details.

The noise model matters: a filter that works well for one type may do poorly on another (slide 5). Why bother? Noise gives false edges in edge detection, splits one object into different regions in segmentation, hides or distorts features in recognition, and small structures can be lost when medical images are denoised (slides 20–21).

The values 100 and +7 are our example.

2 · Two random models: Gaussian (sensor) and Poisson (shot) Topic 4 · slides 6–13

Sensor noise: η ~ N(μ, σ²)f (all 100)100100100100100100+noise η+2−30+1−1+4=g1029710010199104Shot noise: K ~ Poisson(λ), mean = variance = λλ = 10: σ = 3.16σ/λ ≈ 32% of signalλ = 100: σ = 10σ/λ ≈ 10% of signal

Sensor noise: the sensor’s electronics and thermal effects add random variations, most visible in low-light photos (slide 6): high-ISO shots, dark regions, scientific imaging. Slide 7 shows it growing from ISO 100 to ISO 25600. It is modelled as additive Gaussian noise, η ~ N(μ, σ²) (slide 8).

Adding Gaussian noise, step by step (slide 9): 1. choose the distribution (mean 0). 2. draw independent random samples, one per pixel. 3. add the noise matrix to the image. Worked on a 2 × 3 patch of 100s with noise +2, −3, 0, +1, −1, +4 → g = 102, 97, 100, 101, 99, 104.

Shot noise: light arrives as discrete photons, so the count fluctuates, worse in low light (slide 10). K ~ Poisson(λ): K = photons detected, λ = expected count, and mean = variance = λ (slide 11). Slide 12: λ = 10 → σ = √10 = 3.16; λ = 100 → σ = 10. σ is bigger at 100, but relative to the signal it is smaller (3.16/10 ≈ 32% vs 10/100 = 10%), so dim images show shot noise more. Seen in low-light photography, fluorescence microscopy, astronomy (slide 13).

The noise values are our example. Slide 9 literally says “mean and standard deviation of zero”; a σ of 0 would add no noise, so read it as mean 0.

3 · Extreme pixels and multiplied noise: salt & pepper, speckle Topic 4 · slides 14–19

salt & pepper (impulse)6062255610635962600 w.p. pbL−1 w.p. pwf(x,y) elseL = 256 → 255speckleg = f · ηf = 50, η = 1.2g = 60 (+10)f = 200, η = 1.2g = 240 (+40)stray 0s and 255s,the rest untouchedchange grows with f

Transmission and storage errors (transmission errors, defective sensor pixels, processing or storage faults, deliberate corruption) produce extreme or irregular values (slide 14). They are the primary cause of salt and pepper noise, also called impulse noise (slide 15):

g(x,y) = 0 with probability pb (pepper), L − 1 with probability pw (salt), and f(x,y) otherwise. For an 8-bit image L − 1 = 255. So a few pixels jump to black or white and the rest stay exact (slide 16).

Speckle (slides 17–19): coherent systems such as ultrasound and synthetic aperture radar produce a granular pattern. The noise multiplies: g(x,y) = f(x,y) · η(x,y), so the change depends on the pixel value. Worked with η = 1.2: f = 50 → 60 (+10), f = 200 → 240 (+40). Same η, four times the change on the bright pixel.

The window values and η = 1.2 are our examples.

4 · Spatial filters: mean vs Gaussian on one neighbourhood Topic 4 · slides 22–30

one 3 × 3 neighbourhood at an edge (centre = 10)101090101090101090window gmean1111111111/9Gaussian1212421211/16330/9 = 36.7480/16 = 30both pull the dark centre (10) towards the bright sidespatial · linear (mean, Gaussian) · non-linear (median)

Noise filtering reduces unwanted random variation while keeping edges, textures and fine detail (slide 22). Two families: spatial domain (works directly on pixels using neighbours; linear or non-linear) and frequency domain (transform, change the frequency components, transform back) (slide 23). A spatial filter computes a new value from the local neighbourhood: for 3 × 3, the 9 pixels around the centre (slide 24).

Mean (slides 25–26): g′(x,y) = (1/n²) Σi Σj g(x+i, y+j), so for 3 × 3 the kernel is (1/9) × all ones. Worked on the window above: six 10s and three 90s → (60 + 270)/9 = 36.7. Gaussian (slides 28–29): weights from G(x,y) = (1/2πσ²) e−(x²+y²)/2σ², 3 × 3 ≈ (1/16)[1 2 1; 2 4 2; 1 2 1]. Worked: column weights are 4, 8, 4 → (4×10 + 8×10 + 4×90)/16 = 480/16 = 30.

Both are weighted sums, so both pull the dark centre towards the bright side: that is the edge blurring on slides 26–27. The Gaussian moves it less because the centre counts most (4/16 against 1/9). The mean is also pulled hard by outliers (slide 26), and the Gaussian does not reliably remove isolated extreme pixels (slide 30).

5 · The median filter, and which filter for which noise Topic 4 · slides 31–34

median, step by step121511142551310016salt 255 + pepper 01 · sort the 9 values0101112131415162552 · take the 5th (middle) = 13mean = 346/9 = 38.4Gaussian = 72.1 (centre 255 × 4/16)Gaussian → Gaussian/mean · S&P → medianPoisson → Gaussian/mean, Wiener · speckle → Lee/Frost

The median filter sorts the values in the neighbourhood and selects the middle one (slide 31). It is particularly effective against salt and pepper noise, preserves edges better than linear smoothing filters, and is non-linear, so it cannot generally be written as a fixed convolution kernel.

Worked on a window hit by one salt (255) and one pepper (0): 1. list the 9 values. 2. sort: 0, 10, 11, 12, 13, 14, 15, 16, 255. 3. take the 5th: 13. Compare the linear filters on the same window: mean 346/9 = 38.4, Gaussian 1153/16 = 72.1. The extremes sit at the ends of the sorted list and never reach the middle, which is why slide 32’s speckled brain scan comes out clean.

Which filter? (slides 33–34) Gaussian noise → start with Gaussian or mean, move to advanced filters if fine detail must be kept. Salt & pepper → median. Poisson → Gaussian or mean, then specialised ones such as Wiener. Speckle → speckle-specific methods such as Lee or Frost.

The window values are our example.

6 · Cross-correlation vs convolution, worked Topic 4 · slides 35–37

neighbourhood f358269147kernel h (as is)00010−1000h flipped (convolution)000−101000cross-corr: 1×2 + (−1)×9 = −7convolution: (−1)×2 + 1×9 = +7cross-corr: Σ f[m+i, n+j] h[i,j]convolution: Σ f[m−i, n−j] h[i,j]same sum, kernel flippedleft↔right and up↔downasymmetric kernel → sign flips · symmetric (mean, Gaussian) → no difference
swipe to see the whole diagram

Cross-correlation multiplies the neighbourhood by the kernel in its original orientation: (f ∗ h)[m,n] = Σi Σj f[m+i, n+j] h[i,j] (slide 35). Convolution uses the same multiply-and-sum, but the kernel is flipped horizontally and vertically first: Σi Σj f[m−i, n−j] h[i,j] (slide 36).

Worked with i, j ∈ {−1, 0, 1} and the asymmetric kernel h[0,−1] = 1, h[0,1] = −1 (all others 0). Cross-correlation: f[m, n−1]·1 + f[m, n+1]·(−1) = 2 − 9 = −7. Convolution: f[m, n+1]·1 + f[m, n−1]·(−1) = 9 − 2 = +7. Same size, opposite sign, exactly the “sign difference” of slide 37. With a symmetric kernel such as the mean or Gaussian, flipping changes nothing.

Slide 37 also warns that many CV libraries and deep-learning frameworks implement “convolution” that is really cross-correlation: standard CNN layers in PyTorch don’t flip the learned kernel.

The 3 × 3 numbers and kernel are our example. Slide 35 writes cross-correlation with the same ∗ symbol as convolution.

7 · Boundary handling: five answers at one edge pixel Topic 4 · slide 38

image row 5 7 9 …, 1 × 3 mean at the first pixelzero0579(0+5+7)/3 = 4replicate5579(5+5+7)/3 = 5.67reflect7579(7+5+7)/3 = 6.33truncated579(5+7)/2 = 6valid579no output hereyellow = invented outside pixel

An n × n kernel cannot fit inside the image when its centre is near an edge (slide 38). The five strategies: zero padding (pixels outside are 0), replication padding (extend the nearest border pixel outward), reflection padding (reflect the image at its boundary), valid filtering (only output where the whole kernel fits) and truncated kernel (use only the pixels caught inside the image).

Worked on a row starting 5, 7, 9 with a 3-wide mean centred on the first pixel (5): zero → (0 + 5 + 7)/3 = 4, the border darkens. Replicate → (5 + 5 + 7)/3 = 5.67. Reflect → (7 + 5 + 7)/3 = 6.33. Truncated → (5 + 7)/2 = 6. Valid → no value at this pixel, so the output is smaller than the input.

added The 1 × 3 row keeps the arithmetic short; a 3 × 3 kernel works the same way in both directions. “Reflect” here mirrors about the edge pixel; some tools repeat the edge pixel instead.

8 · Exam traps Topic 4 · slides 4, 11–12, 15, 17, 26, 30–31, 36–38 added

  • Additive vs multiplicative: Gaussian sensor noise is g = f + η (slide 4); speckle is g = f · η (slide 17). Only speckle’s change depends on the pixel value.
  • Poisson: mean = variance = λ, so σ = √λ, not λ (slide 11). λ = 100 gives σ = 10.
  • Salt & pepper = impulse noise, caused mainly by transmission/storage errors (slide 15), not by the sensor’s heat.
  • Gaussian filter ≠ cure for salt & pepper: it does not reliably remove isolated extremes (slide 30). Use the median (slide 31).
  • The median is non-linear: no fixed kernel exists for it (slide 31). Mean and Gaussian are linear.
  • Convolution flips the kernel both ways (slide 36). If the kernel is symmetric, convolution and cross-correlation are equal (slide 37).
  • Valid filtering shrinks the output; the padding methods keep its size (slide 38).

9 · Quick check Topic 4 · slides 11–12, 26, 31 added

Q1. λ = 64 photons on average. What are the mean, variance and standard deviation of the count?
Mean = variance = 64, so σ = √64 = 8 (slides 11–12). Relative noise 8/64 = 12.5%.
Q2. A 3 × 3 window holds eight 20s and one 200. Give the 3 × 3 mean and the median.
Mean = (8 × 20 + 200)/9 = 360/9 = 40. Median: sorted, the 5th value is 20 (slides 26, 31). The median ignores the outlier.
Q3. Why can’t the median filter be written as a kernel H like the mean’s (1/9)[1…1]?
Because it sorts and picks the middle value rather than taking a weighted sum; it is non-linear (slide 31).

Exam questions · 16 Practise these 16

Q1What is image noise? Give the additive noise model and state the filtering problem.
Noise is the difference between the recorded pixel values and the values that would ideally represent the scene. It comes from sensor limitations, photon statistics, transmission errors and the imaging process. Additive model: g(x,y) = f(x,y) + η(x,y), observed = original + noise. The filtering problem is to estimate f(x,y) from g(x,y) without removing meaningful image detail (edges, textures). The noise model matters because a filter that suits one type can fail on another.
Q2Describe the four main sources of image noise with their models and where each is seen.
Sensor (Gaussian): electronics and heat; additive η ~ N(μ, σ²); high-ISO and low-light photos, scientific imaging. Photon/shot (Poisson): light arrives as discrete photons; K ~ Poisson(λ) with mean = variance = λ; low light, fluorescence microscopy, astronomy. Transmission/storage (salt & pepper, impulse): corruption, defective pixels, processing faults; isolated extreme values. Imaging process (speckle): coherent systems such as ultrasound and SAR; multiplicative g = f·η, so the change depends on the pixel value.
Q3A pixel receives on average 10 photons per exposure. What are the mean and standard deviation of the count? Why does shot noise show more in dark images?
For Poisson the mean = variance = λ = 10, so σ = √10 ≈ 3.16. At λ = 100, σ = 10. The absolute σ grows with the signal, but the relative noise σ/λ = 1/√λ shrinks: 32% at λ = 10 versus 10% at λ = 100. So images taken in low light show far more noticeable shot noise.
Q4Compare the mean, Gaussian and median filters. Which would you use for salt-and-pepper noise, and why?
Mean: the average of the n × n window (3 × 3 kernel = 1/9 of all ones). Simple, but outliers pull it and it blurs edges because it averages across both sides of a boundary. Gaussian: a weighted average with larger weights near the centre (3 × 3 ≈ 1/16·[1 2 1; 2 4 2; 1 2 1]). Good for Gaussian noise but it does not reliably remove isolated extreme pixels. Median: sort the window and take the middle value. It is non-linear (no fixed kernel), very robust to isolated extremes and keeps edges better. For salt & pepper use the median. Example: a 3 × 3 window of eight 10s and one 255 gives mean ≈ 37 but median = 10.
Q5Distinguish convolution from cross-correlation. When do they give the same result?
Both multiply the neighbourhood by a kernel and sum. Cross-correlation uses the kernel as it is: Σ f[m+i, n+j]·h[i,j]. Convolution flips the kernel horizontally and vertically first: Σ f[m−i, n−j]·h[i,j]. They are identical for symmetric kernels (mean, Gaussian) and differ in sign for asymmetric ones (derivatives). Many CV and deep-learning libraries call cross-correlation "convolution"; standard PyTorch CNN layers don’t flip the learned kernel.
Q6An n × n kernel does not fit at the image border. List the boundary-handling strategies.
Zero padding: assume outside pixels are 0 (can darken borders). Replication padding: extend the nearest border pixel outward. Reflection padding: mirror the image at its boundaries. Valid filtering: compute outputs only where the whole kernel fits (smaller output). Truncated kernel: at the border, use only the kernel pixels that fall inside the image.
Q7Classify · Which noise model fits each case? (a) a high-ISO night photo (b) an astronomy image with very few photons (c) an image sent over a faulty link, with random black and white dots (d) the granular texture of an ultrasound scan (e) a defective sensor pixel.
(a) high-ISO night photoGaussian(b) astronomy, few photonsPoisson(c) faulty link: black/white dotssalt & pepper(d) ultrasound scan grainspeckle(e) stuck sensor pixelsalt & pepper
Topic 4 slides 6, 10–11, 13–15, 17–19 (a) Gaussian sensor noise: high ISO, low light (slide 6). (b) Poisson shot noise: photon-limited imaging, astronomy (slides 11, 13). (c) Salt & pepper: transmission errors cause impulse noise (slides 14–15). (d) Speckle: coherent imaging such as ultrasound (slides 17–19). (e) Salt & pepper: defective sensor pixels are listed with transmission and storage errors (slide 14).
Q8Calculate · Two pixels have f = 80 and f = 160. Find g under additive noise with η = 5, and under speckle noise with η = 1.25. What does the result show?
same pixel pair, two noise modelsf = 80f + 585 (+5)f × 1.25100 (+20)f = 160f + 5165 (+5)f × 1.25200 (+40)additivespeckle
Topic 4 slides 4, 17 Additive, g = f + η: 80 → 85, 160 → 165 (both +5). Speckle, g = f · η: 80 → 100 (+20), 160 → 200 (+40). With additive noise the change is the same everywhere; with speckle it depends on the original pixel value (slide 17), so bright areas change more.
Q9Calculate · One pixel expects λ = 25 photons, another λ = 400. Give the standard deviation of each count and say which will look noisier.
λ = 25σ = √25 = 5σ/λ = 20%λ = 400σ = √400 = 20σ/λ = 5%dim pixel: bigger share of noise
Topic 4 slides 11–12 Poisson: mean = variance = λ, so σ = √λ. λ = 25 → σ = 5; λ = 400 → σ = 20. The bright pixel has the larger σ, but relative to its signal it is smaller: 5/25 = 20% vs 20/400 = 5%. So the dim (λ = 25) pixel looks noisier, which is why shot noise is most noticeable in low light (slides 10, 12).
Q10Apply · Apply the 3 × 3 mean filter and the 3 × 3 Gaussian approximation to the window (20, 22, 24 / 21, 23, 25 / 22, 24, 26). What is the new centre value?
202224212325222426windowsum = 207mean = 207/9 = 23Gaussian:368/16 = 23smooth ramp: no change
Topic 4 slides 25–26, 29 Mean: (1/9) × sum = 207/9 = 23. Gaussian: (1/16)[1 2 1; 2 4 2; 1 2 1]: corners 20 + 24 + 22 + 26 = 92; edges 2 × (22 + 21 + 25 + 24) = 184; centre 4 × 23 = 92; total 368, /16 = 23. Both give 23, the original centre: on a smooth, evenly sloping patch, smoothing changes nothing. The blurring only shows where there are edges or noise.
Q11Calculate · A 3 × 3 window is (50, 52, 0 / 49, 51, 53 / 48, 255, 50). Give the median-filter output and the mean-filter output for its centre. Which is right for this noise?
505204951534825550048495050515253255sortedmedian = 50mean = 608/9 = 67.6
Topic 4 slides 26, 31, 33 Sort: 0, 48, 49, 50, 50, 51, 52, 53, 255 → the 5th value, median = 50. Mean = 608/9 = 67.6, dragged up by the 255. The 0 and 255 are salt and pepper, isolated extremes, so the median is the right choice (slide 33); the mean is strongly affected by outliers (slide 26).
Q12Match · Match each noise type to the filter the slides recommend: Gaussian, salt & pepper, Poisson, speckle.
GaussianGaussian / meansalt & peppermedianPoissonGauss/mean → WienerspeckleLee / Frost
Topic 4 slides 33–34 Gaussian → start with a Gaussian or mean filter, then advanced filters if fine detail must be preserved. Salt & pepper → median, robust to isolated extreme values. Poisson → Gaussian or mean first, then specialised filtering such as the Wiener filter. Speckle → speckle-specific methods such as Lee or Frost, depending on the image model and task.
Q13Explain · Explain why the median filter is called non-linear and cannot be written as a fixed convolution kernel. Use a small example.
1-D, 3 valuesA0 0 9→ median0B9 0 0→ median0A+B9 0 9→ median9median(A)+median(B) = 0 ≠ 9
Topic 4 slides 23, 31 A linear filter (mean, Gaussian) is a fixed weighted sum, so filtering A + B equals filtering A plus filtering B. The median sorts and picks the middle value (slide 31), which breaks this. added Example with three values: median(0, 0, 9) = 0 and median(9, 0, 0) = 0, but median(9, 0, 9) = 9 ≠ 0 + 0. Since no weights could do this, there is no fixed kernel. That is why spatial filters are split into linear and non-linear (slide 23).
Q14Calculate · Neighbourhood f = (4, 7, 2 / 3, 5, 6 / 8, 1, 9) and kernel h with h[−1,0] = 1, h[1,0] = −1, all others 0. Compute the centre output by cross-correlation and by convolution.
472356819f0100000−10hcorr:7 − 1 = 6conv:1 − 7 = −6
Topic 4 slides 35–37 Cross-correlation, Σ f[m+i, n+j] h[i,j]: f[m−1, n]·1 + f[m+1, n]·(−1) = 7 − 1 = 6. Convolution, Σ f[m−i, n−j] h[i,j]: f[m+1, n]·1 + f[m−1, n]·(−1) = 1 − 7 = −6. The kernel is asymmetric, so flipping it changes the sign (slide 37). With a symmetric kernel both would agree.
Q15Describe · Describe the two main types of noise filtering and how each produces its output.
spatial: work on the pixels + neighboursimagetransformmodifybackfrequency domain (slide 23)
Topic 4 slides 22–24 Spatial domain filtering works directly on image pixels: each output pixel is computed from neighbouring pixel values (for 3 × 3, the 9 pixels around the centre), using rules such as the average, median or weighted average. It splits into linear (mean, Gaussian) and non-linear (median) filters. Frequency domain filtering transforms the image into its frequency representation, modifies frequency components, and transforms back to the spatial domain. Both aim to reduce random variation while keeping edges, textures and fine detail (slide 22).
Q16Compare · A 6 × 6 image is filtered with a 3 × 3 kernel. Compare the output size under padding (zero, replication, reflection) and under valid filtering, and say what a truncated kernel does instead.
zero/replicate/reflect6 × 6 outvalid4 × 4a 3 × 3 kernel needs 1 pixel on each side
Topic 4 slide 38 Padding invents the missing outside pixels (zeros, copies of the border, or a mirror), so every pixel gets an output: 6 × 6. Valid filtering only outputs where the whole kernel fits; a 3 × 3 kernel needs one pixel on every side, so the outer ring is lost: 4 × 4. A truncated kernel keeps 6 × 6 without inventing pixels: at the border it uses only the pixels the kernel catches inside the image. added In general the valid size is (6 − 3 + 1) = 4 per side.

Quick MCQs · 14 MCQs in Practise

Not the exam format: quick checks that you understood the topic. Choose 1 or all that apply, then Check.