MCS4304 · Topic 6Hough transform
6
Hough transformpolar form · parameter space · accumulator voting Practise · 15 Qs MCQ · 14

Exam card

  • Problem: edges are local. They don’t say which pixels belong to the same line, or whether a line exists despite gaps, noise or occlusion.
  • y = mx + c fails for vertical lines (infinite slope). Use polar form x cosθ + y sinθ = d: d = perpendicular distance from the origin, θ = angle of that perpendicular to the x-axis.
  • Core idea: image space → parameter space. One point → one sinusoid. Points on the same line → curves that intersect at that line’s (d, θ).
  • Accumulator A(d, θ): a 2-D array of vote counts. Each edge pixel votes for every (d, θ) line through it; a peak = a likely line.
  • Steps: edge pixels → coordinates → sinusoids → vote → peak → (d, θ) → draw the line. Real images: use a threshold A ≥ T (not universal).
  • Extensions: circles (a, b, r: a 3-D accumulator) · probabilistic Hough (random subset, faster, gives segments).

Key diagram

gaps + noise:one line or many?

Key terms

local vs global structureslope–intercept problempolar / normal formx cosθ + y sinθ = dperpendicular distance dangle θimage spaceparameter (Hough) spacesinusoidintersectionaccumulator A(d, θ)votingpeakthreshold Tangle resolutioncircle Houghprobabilistic Hough

What this topic covers

  1. The problem
  2. Why polar form instead of y = mx + c
  3. The Hough accumulator and voting
  4. Finding peaks in real images
  5. Extensions

Deep summary

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

1 · The problem: local edges, global shapes Topic 6 · slides 3–6

edge pixels (local)Houghone line (global)gaps + noise: same line?line found despite gaps

An edge detector tells us where significant intensity changes occur, which pixels probably belong to object boundaries, and where the image has local structure (slide 3; slide 4 shows a car and its edge map).

What edges don’t say (slide 5): whether several edge pixels belong to the same line; whether a set of them forms a common geometric structure; whether a line is present despite gaps, noise or partial occlusion; whether an incomplete boundary belongs to a circle.

So the question of the topic (slide 6): “How can we identify a global geometric structure from a collection of local edge points?”

2 · Three points, and why y = mx + c breaks Topic 6 · slides 7–9

xyP1(1,2)P2(2,3)P3(3,4)x = cy = x + 1m = 1, c = 1through P1 alone:infinitely manyvertical: m = ∞no intercept

Slide 7 gives three edge pixels P1 (1, 2), P2 (2, 3), P3 (3, 4). Step by step (slide 8): 1. slope m = (3 − 2)/(2 − 1) = 1. 2. intercept c = y − mx = 2 − 1 = 1. 3. check P3: 3 + 1 = 4 ✓. So all three lie on y = x + 1. Observation: they share one line. But through any single point, infinitely many lines pass (the grey dashed ones).

y = mx + c has two degrees of freedom (m and c); two points pin them down (slide 9). Now take x = 1: it is vertical, so the slope is infinite and there is no y-intercept. Slope–intercept form cannot write this line, and m has no upper limit. That is the “infinite slope problem” that slide 10 sets out to avoid.

3 · Polar form: d and θ, worked for two lines Topic 6 · slides 10–12

xyOd = 3x = 3, θ = 0°d = 0.71135°y = x + 1x cosθ + y sinθ = d

To avoid the infinite slope, describe a line by its perpendicular distance d from the origin and the angle θ that perpendicular makes with the x-axis (slide 10): x cosθ + y sinθ = d. Both stay finite for every line, vertical ones included.

x = 3 (slide 12): the perpendicular from O runs along the x-axis, so θ = 0° and d = 3. Check: x·cos0° + y·sin0° = x = 3 ✓.

y = x + 1: 1. move everything to one side: −x + y = 1. 2. divide by √((−1)² + 1²) = √2: −0.707x + 0.707y = 0.707. 3. match cosθ = −0.707, sinθ = 0.707 → θ = 135°, d = 1/√2 ≈ 0.71. The perpendicular points up-left to (−0.5, 0.5), which is 0.71 from O.

Slide 11 writes the form as x cosθ − y sinθ = d (image rows grow downwards in its picture); slides 13 and 21 use + y sinθ, which we follow here.

4 · Image space → parameter space: one point, one sinusoid Topic 6 · slides 13–16

0°45°90°135°180°-2024(1,2)(2,3)(3,4)(0.71, 135°)d = x₀cosθ + y₀sinθ for P1, P2, P3d

The core idea (slide 13): convert image space into parameter space (d, θ). For a fixed point (x0, y0), every line through it satisfies x0 cosθ + y0 sinθ = d. Letting θ run gives one curve, a sinusoid (slides 14–15).

Worked for slide 7’s points at θ = 0°, 45°, 90°, 135°: P1 (1, 2) → d = 1, 2.12, 2, 0.71. P2 (2, 3) → 2, 3.54, 3, 0.71. P3 (3, 4) → 3, 4.95, 4, 0.71. At θ = 0°–90° the three values differ; at θ = 135° they agree.

So the three curves intersect at (d, θ) = (0.71, 135°), which is exactly the polar form of y = x + 1 from part 3. That is slide 16: points on the same straight line give curves that meet at a common location in parameter space.

5 · The accumulator: counting votes instead of finding curves Topic 6 · slides 17–19

A(d, θ) for P1, P2, P3 (12 votes in total)110°120°130°12.1245°13.5445°14.9545°1290°1390°1490°30.71135°peak: A(0.71, 135°) = 3 → a line

We know one point gives a sine curve and points on a line give curves that intersect, but it is infeasible to draw infinitely many curves and look for exact intersections (slide 17).

Instead keep an accumulator: a 2-D array A(d, θ) that records how many edge points support each (d, θ) combination, the number of votes it has received (slide 18). Voting (slide 19): each edge pixel casts votes; each vote stands for one line through that pixel; combinations with many votes are likely real lines.

Worked with P1–P3 and 4 angles: 3 points × 4 angles = 12 votes. Nine (d, θ) cells get 1 vote each; the cell (0.71, 135°) gets 3. The peak is the line y = x + 1.

added In practice d is also cut into bins (e.g. whole numbers), so near-equal d values share a cell.

6 · The slide example, step by step Topic 6 · slides 20–24

slide 20 image0000001000001000001000001edge pixels (1,1)…(4,4)(x, y)θ = 0°45°90°135°135°(1,1)11.4110(2,2)22.8320(3,3)34.2430(4,4)45.6640A(0, 135°) = 4back to image:x cos135° + y sin135° = 0−0.707x + 0.707y = 0y = xevery other cell: 1 vote
swipe to see the whole diagram

Slide 20: a 5 × 5 binary edge image, 1 = edge pixel, 0 = background, with edges at (1,1), (2,2), (3,3), (4,4). Use x cosθ + y sinθ = d with θ = 0°, 45°, 90°, 135° (slide 21; real systems use a much finer angle step).

Step by step (slides 22–24): 1. take the edge pixels and their coordinates. 2. for each pixel and each θ compute d: (2,2) at 45° → 2(0.707) + 2(0.707) = 2.83; (2,2) at 135° → 2(−0.707) + 2(0.707) = 0. 3. vote: 16 votes in all. 4. find the peak: d = 0 at 135° for all four pixels, so A(0, 135°) = 4; every other cell has 1. 5. retrieve (d, θ) = (0, 135°). 6. rebuild the line (slide 23): −0.707x + 0.707y = 0 → y = x, the diagonal through every edge pixel.

Slide 24 lists the same seven steps: edge pixels → coordinates → sinusoids → vote → peak → (d, θ) → line in image space.

7 · Reading peaks: max(A) and the threshold T Topic 6 · slides 25–28

slide 25: A0100101000030100max(A) = 3threshold: A(d, θ) ≥ TT = 1 → 5 candidatesT = 2 → 1 candidate (the 3)T = 4 → nonereal images add votes from:noise · several lines · brokenedges · nearby lines · false edges

The accumulator is a matrix of vote counts and max(A) is the strongest line candidate (slide 25). In slide 25’s A, the single 3 (row 3, column 4) wins; every other cell holds 0 or 1.

Real images are not that clean: noise, multiple lines, broken edges, nearby lines and false edges all add or split votes (slide 26). So set a minimum threshold T and keep every cell with A(d, θ) ≥ T as a candidate line (slide 27). On slide 25’s A: T = 1 keeps 5 cells, T = 2 keeps only the 3, T = 4 keeps nothing. T is not universally appropriate: too low gives false lines, too high misses real ones.

Extensions (slide 28): extending the transformation to circles, and the Probabilistic Hough Transformation. The slides only name these.

8 · Exam traps Topic 6 · slides 9–13, 16, 18, 25, 27 added

  • Why polar? Because y = mx + c cannot hold a vertical line (infinite slope), not because polar is “more accurate” (slides 9–10).
  • d and θ are about the perpendicular from the origin to the line, not the line’s own slope angle (slide 10). x = 3 has θ = 0°, not 90°.
  • Sign convention: slide 11 has x cosθ − y sinθ = d; slides 13 and 21 use + y sinθ. Pick one and keep it for the whole answer.
  • One point → one curve (all lines through it); one line → one point (d, θ) where the curves meet (slides 13, 16).
  • A(d, θ) holds vote counts, not pixel intensities (slide 18). The answer is the (d, θ) of the peak, then turned back into a line.
  • Threshold T is a minimum vote count, A ≥ T, and no single T suits every image (slide 27).

9 · Quick check Topic 6 · slides 12–13, 21, 25 added

Q1. Give θ and d for the line y = 4.
The perpendicular from the origin is along the y-axis: θ = 90°, d = 4. Check: x·cos90° + y·sin90° = y = 4 (slides 12–13).
Q2. Point (3, 3): what is d at θ = 45°?
d = 3 cos45° + 3 sin45° = 3(0.707) + 3(0.707) = 4.24 (slide 21 formula).
Q3. An accumulator has values 0, 2, 5, 1, 4, 2. With T = 3, how many candidate lines?
Two: the cells with 5 and 4 are ≥ 3 (slide 27). The strongest is 5 = max(A) (slide 25).

Exam questions · 15 Practise these 15

Q1What problem does the Hough transform solve that an edge detector does not?
An edge detector finds local intensity changes: which pixels are likely to lie on boundaries. It does not say whether several edge pixels belong to the same line or shape, whether a line is present despite gaps, noise or partial occlusion, or whether an incomplete boundary belongs to a circle. The Hough transform finds global geometric structure (lines, circles) from a collection of local edge points, by voting.
Q2Why does the Hough transform use the polar representation of a line? Give the polar form of x = 3 and y = x + 1.
Slope–intercept y = mx + c cannot represent vertical lines (m → ∞), and m is unbounded, so it can’t be put into a finite accumulator. The polar form x cosθ + y sinθ = d uses the perpendicular distance d from the origin and the angle θ of that perpendicular to the x-axis. Both are bounded, so every line fits. x = 3 → θ = 0°, d = 3. y = x + 1 → −x + y = 1; dividing by √2 gives x cos135° + y sin135° = 1/√2, so θ = 135°, d ≈ 0.71.
Q3Explain the mapping from image space to parameter space and why points on a line meet at one point.
For a fixed edge point (x₀, y₀), every line through it satisfies x₀ cosθ + y₀ sinθ = d. As θ varies, this traces a sinusoid in (θ, d) space, which stands for all lines through that point. A particular line (d*, θ*) passes through all its points, so every one of their sinusoids goes through (θ*, d*). Points on the same line give curves that intersect at a common location, and that location is the line’s parameters.
Q4Given edge pixels (1,1), (2,2), (3,3), (4,4) and θ ∈ {0°, 45°, 90°, 135°}, use a Hough accumulator to find the line.
d = x cosθ + y sinθ. θ = 0°: d = 1, 2, 3, 4 (one vote each). θ = 45°: d = 1.41, 2.83, 4.24, 5.66 (one each). θ = 90°: d = 1, 2, 3, 4 (one each). θ = 135°: d = 0 for all four, so A(0, 135°) = 4, the peak. The line is x cos135° + y sin135° = 0 → −x + y = 0 → y = x.
Q5What is the Hough accumulator? How are peaks chosen in real images, and what extensions exist?
The accumulator A(d, θ) is a 2-D array that counts how many edge points support each discretised (d, θ) pair. Each edge pixel votes once per θ (one candidate line through it). max(A) is the strongest line, but real images have noise, several lines, broken edges, nearby lines and false edges, so a threshold T is applied (A ≥ T → candidate line). T is not universally right and depends on the image and line length. Extensions: circles (parameters a, b, r, a 3-D accumulator) and the probabilistic Hough transform (a random subset of points: faster, and gives segments).
Q6Calculate · For the edge point (2, 1), compute d = x cosθ + y sinθ at θ = 0°, 45°, 90° and 135°.
θ0°45°90°135°d22.121−0.71point (2, 1): x cosθ + y sinθd < 0 at 135°: the perpendicular points the other way
Topic 6 slides 13, 21 θ = 0°: 2(1) + 1(0) = 2. θ = 45°: 2(0.707) + 1(0.707) = 2.12. θ = 90°: 2(0) + 1(1) = 1. θ = 135°: 2(−0.707) + 1(0.707) = −0.71. These four (d, θ) pairs are the four votes this pixel casts (slide 19). added A negative d just means the perpendicular from the origin points in the opposite direction.
Q7Apply · Rebuild the image-space line from each accumulator peak: (a) θ = 0°, d = 4 (b) θ = 90°, d = 2 (c) θ = 45°, d = 1.41.
θ = 0°, d = 4x = 4θ = 90°, d = 2y = 2θ = 45°, d = 1.41x + y = 2
Topic 6 slides 23–24 Put the values into x cosθ + y sinθ = d. (a) cos0° = 1, sin0° = 0 → x = 4 (vertical). (b) cos90° = 0, sin90° = 1 → y = 2 (horizontal). (c) 0.707x + 0.707y = 1.41 → divide by 0.707 → x + y = 2. This is step 7 of slide 24: reconstruct the line in image space.
Q8Calculate · Edge pixels (2, 0), (2, 1) and (2, 3). Using θ = 0°, 45°, 90°, 135°, fill the d table, find the accumulator peak and the line.
(x, y)0°45°90°135°(2,0)21.410−1.41(2,1)22.121−0.71(2,3)23.5430.71peak A(2, 0°) = 3 → x = 2
Topic 6 slides 20–23 θ = 0°: d = 2, 2, 2. θ = 45°: 1.41, 2.12, 3.54. θ = 90°: 0, 1, 3. θ = 135°: −1.41, −0.71, 0.71. Only (d = 2, θ = 0°) appears three times, so A(2, 0°) = 3 is the peak. Line: x cos0° + y sin0° = 2 → x = 2, a vertical line, which y = mx + c could not even write (slide 9).
Q9Explain · Explain the problem with slope–intercept form for the line x = 1, and how the polar representation removes it.
x = 1y = mx + c ?m = Δy/Δx = Δy/0→ infiniteno y-intercept cpolar: θ = 0°, d = 1
Topic 6 slides 9–11 Slope–intercept y = mx + c uses two degrees of freedom, m and c. On x = 1 every point has the same x, so m = Δy/Δx divides by zero: the slope is infinite, and the line never crosses the y-axis, so there is no c (slide 9). The polar form uses the perpendicular distance d from the origin and its angle θ to the x-axis (slide 10), which are finite for every line: x = 1 is simply θ = 0°, d = 1.
Q10Classify · Image space or parameter space? (a) an edge pixel (x, y) (b) the sinusoid traced by one point (c) the line y = x (d) a peak in the accumulator (e) a (d, θ) pair (f) the gaps in a broken edge.
IMAGE SPACEPARAMETER SPACE(a) edge pixel (x, y)(c) the line y = x(f) gaps in an edge(b) a sinusoid(d) a peak in A(e) a (d, θ) pair
Topic 6 slides 13–18 Image space: (a), (c), (f): things you can see in the picture. Parameter space: (b), (d), (e): one point becomes a curve of all (d, θ) lines through it, and the accumulator A(d, θ) lives here too. The Hough transform goes image → parameter (vote) and then back to image (draw the line) (slides 13, 24).
Q11Outline · These steps are shuffled: find the peak; transform each coordinate into a sinusoid; obtain edge pixels; reconstruct the line; extract coordinates; retrieve (d, θ); let the curves vote. Put them in order.
1 · Obtain edge pixels2 · Extract coordinates3 · Each → a sinusoid4 · Curves vote in A5 · Find the peak6 · Read (d, θ)7 · Rebuild the line
Topic 6 slide 24 1. Obtain edge pixels. 2. Extract their coordinates. 3. Transform each coordinate into a sinusoidal curve in parameter space. 4. Let the curves vote in an accumulator. 5. Identify the accumulator peak. 6. Retrieve the corresponding (d, θ). 7. Reconstruct the line in image space. Memory aid: edges → numbers → curves → votes → peak → parameters → line.
Q12Calculate · An accumulator is A = (0, 2, 1 / 4, 0, 3 / 1, 5, 0). What is the strongest candidate? How many candidate lines are there with T = 3, and with T = 5?
021403150max(A) = 5T = 3 → 3 candidates(5, 4 and 3)T = 5 → only the 5
Topic 6 slides 25, 27 The strongest candidate is max(A) = 5 (row 3, column 2) (slide 25). With T = 3, keep cells with A ≥ 3: 4, 3 and 5, so 3 candidates (slide 27). With T = 5 only the 5 is left: 1 candidate. Lowering T admits weaker lines (and more false ones); raising it may drop real lines.
Q13Explain · Explain why the Hough transform uses an accumulator of votes rather than searching for the exact intersections of the curves, and what the angle step on slide 21 has to do with it.
exact intersections∞ curves: infeasibleaccumulator grid010110130101count votes per cell
Topic 6 slides 17–19, 21 Every edge point gives a whole curve, and a line is where curves cross. Generating infinitely many curves and finding their exact intersections is infeasible (slide 17). So (d, θ) is turned into a finite 2-D array A(d, θ): each edge pixel votes for the cells of the lines through it, and cells with many votes are likely lines (slides 18–19). The θ values checked are the columns of that array: the example uses 0°, 45°, 90°, 135°, while real systems use a much finer angle resolution (slide 21).
Q14Describe · Describe why picking just max(A) is not enough on real images, and how the threshold T is used.
noisemultiple linesbroken edgesnearby linesfalse edgesmessy votes → keep A(d, θ) ≥ Tbut no single T suits every image
Topic 6 slides 25–27 max(A) is the strongest single candidate (slide 25), but a real image may hold several lines, and noise, broken edges, nearby lines and false edges add stray votes or split a line’s votes (slide 26). So a minimum threshold is set: every cell with A(d, θ) ≥ T is a candidate line (slide 27). T is not universally appropriate: it has to be chosen for the image.
Q15Compare · Compare what an edge detector gives you with what the Hough transform gives you. Why do you need both?
edge detectorlocal: pixel by pixelintensity changeslikely boundariesHough transformglobal: whole shapeswhich pixels share a lineworks across gaps
Topic 6 slides 3–6, 13, 24 An edge detector is local: it marks where intensity changes sharply and which pixels are likely on boundaries (slide 3). It cannot say which pixels belong to the same line or whether a line continues across gaps, noise or occlusion (slide 5). The Hough transform is global: it maps those edge pixels into parameter space and votes, so a line supported by many pixels wins even if it is broken (slides 13, 19). You need both: Hough step 1 is “obtain edge pixels” (slide 24).

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.