Quiz: edges, Gaussian derivatives and Canny
Before this unit: Day 1: Images, filters and frequencies.
Short questions to test your understanding. Try each on paper first, then open the answer. Convention: x to the right, y down; L_y is the change going down; angles are counter-clockwise on the screen.
Q1. Why do we smooth an image before taking derivatives? What is lost by smoothing?
What does a difference of neighbours do to a pixel that differs from its neighbours?
A derivative is a difference of neighbouring pixels, and noise is exactly pixels that differ from their neighbours: the derivative amplifies it. Smoothing first averages the noise away. The price: edges get wider, corners round off, and edges closer than about 2σ merge into one.
Q2. A Gaussian kernel with σ = 3 is cut at 4σ. How many taps does it have? How many multiplications per pixel does a 2D blur need, done directly and done separably?
Taps from −4σ to +4σ. Separable: one pass along rows, one along columns.
2 \cdot 12 + 1 = 25 taps. Directly 25^2 = 625 multiplications per pixel; separably 2 \cdot 25 = 50.
Q3. “Smooth, then differentiate” needs two filters. Why can it be done with one kernel, and what does that kernel look like?
Applying two kernels one after the other is the same as applying their convolution.
Convolutions combine: applying the Gaussian and then the difference kernel equals applying their convolution once. The result is the derivative of a Gaussian: a positive lobe on one side and a negative lobe on the other, “right minus left, with Gaussian weights”. In 2D, G_x is this 1D kernel along x times a plain Gaussian along y, like a large, smooth Sobel kernel.
Q4. At a pixel L_x = -6 and L_y = 8. What are the edge strength and the gradient direction? Which side of the edge is brighter?
y points down, so L_y > 0 means brighter further down.
Strength \sqrt{36 + 64} = 10. The gradient points left and down; counter-clockwise on the screen, \theta = \operatorname{atan2}(-8, -6) = -126.9° (or 233.1°). The brighter side is to the lower left. The edge itself runs perpendicular to this, from lower right to upper left.
Q5. After non-maximum suppression, why is an edge one pixel wide? Which two pixels is a pixel compared with?
Across the edge the magnitude is a ridge.
Across an edge, the gradient magnitude rises to a crest and falls again. NMS keeps a pixel only if its magnitude is at least that of its two neighbours along the gradient direction (rounded to 0°, 45°, 90° or 135°), i.e. across the edge. Only the crest pixel survives on each cross-section. Pixels along the edge are not compared with each other, so the edge stays connected.
Q6. With t_\text{low} = 4 and t_\text{high} = 10: a pixel of magnitude 6 (after NMS) is kept in one place and removed in another. How can that be?
Hysteresis looks at the neighbours too.
6 is a weak value (between the thresholds). A weak pixel is kept only if it is connected, through pixels of at least 4, to a seed of at least 10. On a faint stretch of a real edge it hangs on to the strong parts and is kept; as an isolated noise pixel it has no seed and is removed.
Q7. Canny finds a ragged mess of short edges in a noisy image. Which parameter would you change first, and in which direction?
Noise edges come from small structures.
Increase σ: more smoothing removes the noise before the gradient is taken. (Raising t_\text{low} also removes noise chains, but leaves the edges themselves noisy.) Watch for the price: corners rounding off and close edges merging.
Q8. (math) Show that the derivative of the Gaussian g_\sigma(x) = \frac{1}{\sqrt{2\pi}\sigma}e^{-x^2/2\sigma^2} is -\frac{x}{\sigma^2}g_\sigma(x). Where are its extremes?
Chain rule; then set the derivative of x e^{-x^2/2\sigma^2} to zero.
\frac{d}{dx}e^{-x^2/2\sigma^2} = -\frac{x}{\sigma^2}e^{-x^2/2\sigma^2}, so g'_\sigma = -\frac{x}{\sigma^2}g_\sigma. Extremes where \frac{d}{dx}(x e^{-x^2/2\sigma^2}) = (1 - x^2/\sigma^2)e^{-x^2/2\sigma^2} = 0: at x = \pm\sigma. The two lobes of the kernel sit one σ either side of the centre.