MCS4304 · Topic 2Visual perception & image sensing
2
Visual perception & image sensinglight · sensing · sampling & quantization · histograms · equalisation Practise · 15 Qs MCQ · 14

Exam card

  • Light = the part of the EM spectrum the eye senses. The colour we see = the light reflected. Monochromatic = grey level only. Chromatic adds radiance (W), luminance (lm), brightness.
  • Acquisition: single sensor (moves in x and y) · sensor strip (a line at a time) · sensor array (2-D grid, cameras).
  • Image formation model: f(x,y) = i(x,y) · r(x,y), illumination × reflectance.
  • Sampling digitises the coordinates. Quantization digitises the intensity. Rounding to the nearest level causes quantization error. Result = a 2-D array; 8-bit = 256 levels (0 black, 255 white).
  • Histogram h(rk) = nk, the pixel count per intensity level. Its shape shows dark, bright and low- or high-contrast images.
  • Contrast stretching: Iout = (Iin−c)(b−a)/(d−c)+a. Outliers spoil it, so use the 5th/95th percentiles or a cut-off. Equalisation: sk = Σ ni/n, new = round(sk·m).

Key diagram

γ / X-rayUVIRradiovisible lightcolour seen = light reflected

Key terms

electromagnetic spectrummonochromatic / chromatic lightradiance · luminance · brightnesssingle sensor · strip · arrayf = i · rilluminationreflectancesamplingquantizationquantization error2-D arrayh(rk) = nkcontrast stretching5th / 95th percentilehistogram equalisationcumulative distribution

What this topic covers

  1. Light and the electromagnetic spectrum
  2. Image sensing and acquisition
  3. Sampling and quantization
  4. The intensity histogram
  5. Enhancement 1: contrast stretching
  6. Enhancement 2: histogram equalisation (worked example from the slides)

Deep summary

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

1 · Light: the part of the spectrum we can see Topic 2 · slides 3–5

EM spectrum (slide 3)gammaX-rayUVIRmicroradiovisibleshort λ · high f · high energylong λ · low f · low energyMonochromaticno colour:grey level onlyChromatic (colour)frequency, plusradiance · wattsluminance · lumensbrightness

The electromagnetic spectrum can be described by wavelength, frequency or energy (slide 4). Going left on slide 3 (towards gamma rays) means shorter wavelength, higher frequency and higher energy; going right (towards radio) the opposite. Light is the small band the human eye can sense.

The colour we see in an object is set by the light reflected from it (slide 4). Slide 5 then splits light in two: monochromatic light has no colour, and its intensity is given as a grey level. Chromatic (colour) light needs frequency plus three quantities: radiance (watts), luminance (lumens) and brightness.

The slides give only the names and units of the three quantities, so learn them as a list of three.

2 · Sensors, and the simple image formation model Topic 2 · slides 6–9

1 · single sensorxymoves in x and y(slide 7)2 · sensor stripa line of sensors(listed on slide 6)3 · sensor arraya 2-D array(slide 8)f(x,y) = i(x,y) · r(x,y)irfi = 200r = 0.5f = 100darker surface: r = 0.2 → f = 40half the light: i = 100 → f = 50value ∝ energy from the source
swipe to see the whole diagram

Image acquisition transforms illumination energy into a digital image (slide 6). Slide 6 lists three arrangements: (1) a single sensor, which has to move in x and y to build up the 2-D image (slide 7: energy passes a filter onto the sensing material, which gives out a voltage waveform); (2) sensor strips; (3) sensor arrays, sensors arranged as a 2-D array (slide 8).

Formation model (slide 9): intensity values are proportional to the energy radiated from the physical source, written f(x,y) = i(x,y) r(x,y). Worked: i = 200 and r = 0.5 give f = 200 × 0.5 = 100. A darker surface (r = 0.2) gives 40; halving the light (i = 100) gives 50.

Calling i “illumination” and r “reflectance” is the usual reading; slide 9 gives only the formula. The numbers are our example.

3 · Sampling: digitise the coordinates, get a 2-D array Topic 2 · slides 10–13, 19–20

continuous10 × 10 samplessamplef(0,0) … f(M−1, N−1): here M = N = 10 → 100 samples

A sensor outputs a continuous waveform, so making a digital image takes two processes: sampling and quantization (slide 10). The image is continuous in x, y and in amplitude; sampling digitises the x and y coordinates (slide 11).

Step by step (slide 12): 1. lay a grid over the image, 10 on x and 10 on y. 2. take one value per cell: 10 × 10 = 100 samples = 100 pixels. 3. more pixels means more samples, so finer detail. Slide 13 shows the same idea: a smooth shape becomes blocks.

The result is the image as a 2-D array (slide 19): f(x,y) has rows f(0,0) … f(0,N−1) down to f(M−1,0) … f(M−1,N−1), so M × N samples. For a 10 × 10 grid, x and y each run 0…9. Slide 20 shows a digit drawn on a grid next to its numbers (0.0 = black, 1.0 = white).

4 · Quantization, and the error it leaves Topic 2 · slides 14–18

snap each sample to the nearest level01234567true valuelevel givenerrorsampletruelevelerror10.810.222.320.334.650.446.160.155.250.2error never above half a step (0.5)
swipe to see the whole diagram

Quantization digitises the amplitude. Slides 14–16 take the intensity along a line A–B through the image: the profile is continuous, sampling picks points along it, and each point is then put on a grey scale.

Step by step (slide 17): 1. divide the range from black to white into equal parts. 2. each continuous value is given one of the discrete values. 3. which one depends on the vertical proximity of the sample to the levels, so take the nearest. Worked with levels 0–7: 0.8 → 1, 2.3 → 2, 4.6 → 5, 6.1 → 6, 5.2 → 5.

The gap between the true value and the level it gets is the quantization error (slide 18 shows it as a staircase hugging a smooth curve, with binary codes 0000, 0001 … on the levels). Here the errors are 0.2, 0.3, 0.4, 0.1, 0.2.

added With nearest-level rounding the error is never more than half a step; more levels means smaller steps and smaller error.

5 · The histogram: count the pixels at each level Topic 2 · slides 21–27

4 × 4 image, levels 0–71122122322330237n = 16 pixelsh(rk) = nk1031724345617intensity level rk

For levels in [0, L−1] the histogram is h(rk) = nk: rk is the k-th intensity and nk is how many pixels have it (slide 21). The x-axis is the intensity level and the y-axis is the number of pixels (slides 22–23). An 8-bit grey image has 256 levels, 0 = black and 255 = white (slide 23).

Step by step on a 4 × 4 image with levels 0–7: 1. go through all 16 pixels. 2. tally each value: level 0 → 1, level 1 → 3, level 2 → 7, level 3 → 4, level 7 → 1, the rest 0. 3. check: 1 + 3 + 7 + 4 + 1 = 16 = number of pixels. 4. draw a bar per level.

Reading the shape (slides 24–27): bunched at the low end = dark image; at the high end = bright; squeezed into a narrow band = low contrast; spread across 0–255 = high contrast. Our image sits mostly on levels 1–3, so it is dark and low in contrast, with one lone pixel at 7.

6 · Contrast stretching, one pixel at a time Topic 2 · slides 28–30

Iout = (Iin − c)(b − a)/(d − c) + a72 → 5190 → 127.5108 → 2040c=60d=120255a=0b=255Iin

Contrast stretching stretches the range of intensities from its original range [c, d] to span the desired range [a, b] (slides 28–29): Iout = (Iin − c)(b − a)/(d − c) + a. On slide 29, c and d mark where the histogram starts and ends, and a = 0, b = 255 are the ends of the scale.

Worked (c = 60, d = 120, a = 0, b = 255): 1. scale = (b − a)/(d − c) = 255/60 = 4.25. 2. for each pixel subtract c, multiply by 4.25, add a. Iin = 72: (72 − 60) × 4.25 = 51. Iin = 90: 30 × 4.25 = 127.5. Iin = 108: 48 × 4.25 = 204. The ends go 60 → 0 and 120 → 255.

Problem: outliers (slide 30). Add one pixel at 0 and one at 255: if c and d are the min and max, then c = 0, d = 255, the scale is 1 and nothing changes. Fixes: take c and d at the 5th and 95th percentiles of the histogram, or take the histogram peak, define a cut-off and ignore the data below it.

added Values below c or above d are usually clipped to a and b (the grey dashed ends).

7 · Histogram equalisation on the slide 34 table Topic 2 · slides 31–34

before (slide 34) · n = 4096, m = 7after equalisation79001023185026563329424551226817079012102334850598564487new level: 0→1 · 1→3 · 2→5 · 3→6 · 4→6 · 5→7 · 6→7 · 7→7
swipe to see the whole diagram

Equalisation spreads out the most frequent intensities through the intensity range (slide 31: the dull car photo becomes clear). Notation (slide 32): n pixels, grey levels 0…m, nk pixels at level k, probability nk/n. Transform (slide 33): sk = Σi=0..k ni/n, and the new value is round(sk × m).

Step by step on slide 34: 1. n = 790 + 1023 + … + 81 = 4096; levels 0–7, so m = 7. 2. running total of nk: 790, 1813, 2663, 3319, 3648, 3893, 4015, 4096. 3. divide by 4096: s0 = 0.193, s1 = 0.443, s2 = 0.650 … s7 = 1. 4. × 7 and round: 0.193 × 7 = 1.35 → 1; 0.443 × 7 = 3.10 → 3; 0.650 × 7 = 4.55 → 5; and so on (full table above).

5. move the counts: level 6 gets 656 + 329 = 985 and level 7 gets 245 + 122 + 81 = 448. The bars now use levels 1–7, and the busy dark levels are pushed apart.

8 · Exam traps Topic 2 · slides 11, 17, 21, 23, 28, 33 added

  • Sampling vs quantization: sampling digitises the coordinates (how many pixels); quantization digitises the amplitude (how many grey levels). Don’t swap them (slides 11, 17).
  • 8-bit = 256 levels numbered 0–255, 0 black and 255 white (slide 23), not 1–256.
  • nk is a count of pixels, not an intensity. The bars of a histogram add up to n (slide 21).
  • Stretching: subtract c (the input low end), divide by (d − c), then add a (slide 28). Mixing up a/c is the usual slip.
  • Equalisation: use the running sum of ni/n, and multiply by m, the top level (7 for levels 0–7), not by the number of levels 8 (slide 33).
  • Equalisation can merge levels (3 and 4 both go to 6) but never splits one level into two.

9 · Quick check Topic 2 · slides 12, 23, 28, 33–34 added

Q1. A 16 × 16 sampling grid with 4-bit levels: how many samples, and how many grey levels?
16 × 16 = 256 samples (slide 12 logic). 4 bits give 24 = 16 levels, 0–15 (slide 23 does the 8-bit case: 256 levels).
Q2. Stretch [c, d] = [20, 70] to [a, b] = [0, 250]. What is Iout for Iin = 45?
(45 − 20) × 250/50 + 0 = 25 × 5 = 125 (slide 28).
Q3. In the slide 34 example, why does level 0 become 1 and not stay 0?
s0 = 790/4096 = 0.193, and 0.193 × 7 = 1.35, which rounds to 1 (slide 33). Level 0 holds about a fifth of the pixels, so it moves up.

Exam questions · 15 Practise these 15

Q1Explain image sampling and quantization. What is quantization error?
A sensor outputs a continuous signal. Sampling digitises the spatial coordinates (x, y), so it decides how many pixels there are: more samples means more spatial detail. Quantization digitises the amplitude: the intensity range is split into equal discrete levels and each sample takes the nearest level. Quantization error is the difference between the true continuous value and the level it was given. Fewer levels means a bigger error and visible banding.
Q2Describe the three ways of acquiring an image and the simple image formation model.
(1) A single sensor that must move in x and y to build up the 2-D image. (2) A sensor strip that captures a line at a time while it or the object moves. (3) A sensor array, a 2-D grid that captures the whole frame at once (cameras). Formation model: f(x,y) = i(x,y)·r(x,y), the illumination falling on the scene times the reflectance of the surface. Intensities are proportional to the energy radiated from the source.
Q3Define the intensity histogram. What does it tell you about an image?
For levels in [0, L−1], h(rk) = nk: the number of pixels with intensity rk (x-axis = level, y-axis = count). Bunched at the low end means a dark image, at the high end a bright image, and in a narrow band low contrast. Spread across the range means high contrast. Normalising, p(rk) = nk/n, gives the probability of each level.
Q4Apply contrast stretching: input range [50, 150] mapped to [0, 255]. What is the output for 100? What is the weakness of the method, and how is it fixed?
Iout = (Iin − c)(b − a)/(d − c) + a = (100 − 50)(255 − 0)/(150 − 50) + 0 = 127.5 (about 128). Weakness: outliers. One extreme pixel sets c or d, and the stretch then has almost no effect. Fixes: choose c and d at the 5th and 95th percentiles of the histogram, or take the histogram peak, set a cut-off and ignore data below it.
Q5Histogram-equalise an 8-level image (n = 4096) with nk = 790, 1023, 850, 656, 329, 245, 122, 81.
Cumulative: 790, 1813, 2663, 3319, 3648, 3893, 4015, 4096. sk = cum/4096: 0.193, 0.443, 0.650, 0.810, 0.891, 0.950, 0.980, 1.000. × m (7) and round: 0→1, 1→3, 2→5, 3→6, 4→6, 5→7, 6→7, 7→7. The new histogram has 790 at level 1, 1023 at 3, 850 at 5, 985 at 6 and 448 at 7. It now covers the range much more evenly.
Q6Calculate · Using the simple image formation model, a surface with r(x,y) = 0.6 is lit with i(x,y) = 150. What is f(x,y)? What is f if the light is halved?
i=150r = 0.6f = 90dimmer light: i = 75 → f = 45f = i × r (slide 9)
Topic 2 slide 9 f(x,y) = i(x,y) r(x,y) = 150 × 0.6 = 90. Halving the light gives i = 75, so f = 75 × 0.6 = 45. The value recorded follows the energy reaching the sensor, so it halves too. Exam tip: write the formula first, then substitute.
Q7Classify · Sampling or quantization? (a) choosing a 10 × 10 grid of pixels (b) using 256 grey levels (c) digitising the x and y coordinates (d) giving each value the level it is vertically closest to (e) the difference between the true value and the stored level.
SAMPLING (x, y)QUANTIZATION(a) 10 × 10 grid(c) digitise x, y(b) 256 levels(d) nearest level(e) error
Topic 2 slides 11–12, 17–18 Sampling: (a) and (c), because they decide where values are taken. Quantization: (b), (d) and (e), because they decide which value is stored and what is lost doing it (quantization error). The rule: positions → sampling; intensity → quantization.
Q8Outline · Outline the difference between monochromatic and chromatic light, naming the quantities used to describe a chromatic light source.
monochromaticno colourgrey levelchromatic+ frequencyradiance (W)luminance (lm)brightness
Topic 2 slides 4–5 Monochromatic light is void of colour; its intensity is given by a grey level. Chromatic light is colour light; besides its frequency, three basic quantities describe the source: radiance (watts), luminance (lumens) and brightness. Light itself is the part of the EM spectrum the eye can sense, and the colour of an object comes from the light it reflects.
Q9Calculate · A 0–255 range is quantized to four equal levels: 0, 85, 170, 255. Quantize the samples 30, 100, 140 and 240 and give the quantization error of each.
08517025530→0100→85140→170240→255error: 30 · 15 · 30 · 15
Topic 2 slides 17–18 Give each sample the level it is vertically closest to: 30 → 0 (error 30), 100 → 85 (error 15), 140 → 170 (error 30), 240 → 255 (error 15). The quantization error is the gap between the true value and the stored level. With only four levels the steps are 85 apart, so errors up to 42.5 are possible; more levels means smaller errors.
Q10Match · Match each histogram shape to an image: (A) piled up at the left (B) piled up at the right (C) a narrow hump in the middle (D) spread over the whole range. Images: bright, high contrast, dark, low contrast.
ABCDA dark · B bright · C low contrast · D high contrast
Topic 2 slides 24–27 A → dark (most pixels near 0, slide 24). B → bright (near 255, slide 25). C → low contrast (a narrow band of levels, slide 26). D → high contrast (spread across 0–255, slide 27). Remember the axes (slide 23): x = intensity, y = number of pixels.
Q11Calculate · A 3 × 3 image has rows (0, 0, 1), (1, 1, 2), (3, 1, 0) with levels 0–3. Give h(rk) for each level and the probability nk/n.
00111231030411213p(rk) = nk/n: 3/9, 4/9, 1/9, 1/9
Topic 2 slides 21, 32 n = 9 pixels. Tally: level 0 → 3, level 1 → 4, level 2 → 1, level 3 → 1 (check: 3 + 4 + 1 + 1 = 9). Probabilities nk/n: 0.333, 0.444, 0.111, 0.111 (they add up to 1). The image is mostly dark: 7 of 9 pixels sit at levels 0–1.
Q12Apply · An image only uses intensities 40–200. Stretch it to 0–255 and find Iout for Iin = 80 and Iin = 120.
80→63.75120→127.5c=40d=2002550scale = 255/160 ≈ 1.594
Topic 2 slides 28–29 Here c = 40, d = 200, a = 0, b = 255, so Iout = (Iin − 40) × 255/160. Iin = 80: 40 × 255/160 = 63.75 ≈ 64. Iin = 120: 80 × 255/160 = 127.5 ≈ 128. Check the ends: 40 → 0 and 200 → 255. Write c, d, a, b down before substituting.
Q13Explain · A photo has almost all its pixels between 90 and 160, but one stuck pixel is 0 and one is 255. Explain why plain contrast stretching fails here and how the slides fix it.
02555th95thmin/max: c = 0, d = 255 → no changepercentiles: c, d hug the real data
Topic 2 slide 30 If c and d are taken as the smallest and largest values, the two outliers give c = 0 and d = 255. With a = 0, b = 255 the formula becomes Iout = Iin, so the image is unchanged. Fixes (slide 30): pick c and d at the 5th and 95th percentiles of the histogram (about 90 and 160 here), or find the histogram peak, set a cut-off, and ignore the data below it.
Q14Calculate · Equalise a 16-pixel image with levels 0–3 (m = 3) and nk = 6, 6, 3, 1.
before60613213after0616243map 0→1 · 1→2 · 2→3 · 3→3
Topic 2 slides 32–33 Running totals: 6, 12, 15, 16. sk = total/16: 0.375, 0.75, 0.9375, 1. × m = 3: 1.125, 2.25, 2.81, 3. Round: 0 → 1, 1 → 2, 2 → 3, 3 → 3. New histogram: level 1 = 6, level 2 = 6, level 3 = 3 + 1 = 4. Levels 2 and 3 have merged, and the busy dark levels are pushed up the scale.
Q15Compare · Compare contrast stretching and histogram equalisation: what each uses from the histogram, the shape of the mapping, and one weakness.
stretchingstraight line c,d → a,bequalisationcurve from running sum
Topic 2 slides 28–33 Stretching uses only two points of the histogram, c and d, and maps [c, d] to [a, b] with a straight line. It is spoiled by outliers unless c and d come from percentiles or a cut-off. Equalisation uses the whole histogram: the mapping is round(sk × m) with sk the running sum of ni/n, so busy levels get spread out. Its weakness added: rounding can merge levels, and you don’t choose the output range.

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.