Machine Vision — Answer Key
Based on Lecture Notes #3
Notes: numeric rounding is shown to 4 decimal places where requested.
Q1. (Cross-correlation — center pixel)
Given
4 2 1 1 0 −1
X = 0 3 2 , h = 2 0 −2 .
1 1 0 1 0 −1
Cross-correlation at the center = element-wise product sum:
X
Xij hij
i,j
Compute row-wise:
Row 1: 4 · 1 + 2 · 0 + 1 · (−1) = 4 + 0 − 1 = 3,
Row 2: 0 · 2 + 3 · 0 + 2 · (−2) = 0 + 0 − 4 = −4,
Row 3: 1 · 1 + 1 · 0 + 0 · (−1) = 1 + 0 + 0 = 1.
Total: 3 + (−4) + 1 = 0.
Q2. (Gaussian kernel)
For σ = 1,
1 −(x2 +y2 )/2
G(x, y) = e .
2π
1
(a) G(0, 0) = .
2π
1
≈ 0.1591549431 ⇒ 0.1592 .
2π
1 −((1)2 +(1)2 )/2 1 −1
(b) G(1, 1) = e = e .
2π 2π
1 −1
e ≈ 0.0585498315 ⇒ 0.0585 .
2π
1
Q3. (Box smoothing then horizontal Sobel)
We compute (I ∗Box)∗Sobelx using zero-padding (standard discrete convolution with border
= 0).
Given
10 10 20 1 1 1
1
I = 20 30 40 , Box = 1 1 1 ,
9
10 15 25 1 1 1
−1 0 1
Sobelx = −2 0 2 .
−1 0 1
Step 1: Convolve I with Box (zero-padding). The smoothed image (values shown to
high precision) is
7.77777778 14.44444444 11.11111111
Ismoothed = 10.55555556 20.00000000 15.55555556 .
8.33333333 15.55555556 12.22222222
Step 2: Convolve Ismoothed with Sobelx (zero-padding). The center (row 2, col 2) result
is
155
= 17.22222222 . . . .
9
(rounded if desired: 17.2222 )
Remark: you may obtain the same center value by direct sequential convolution or by
using associativity I ∗ (Box ∗ Sobelx ) and evaluating at the center.
Q4. (2×2 DFT)
Image: " #
1 0
I= , M = N = 2.
0 1
2-D DFT (normalization 1/(M N )):
1 1
1XX nu mv
F (u, v) = I(n, m) e−2πi( 2 + 2 ) .
4 n=0 m=0
Non-zero image entries at (0, 0) = 1 and (1, 1) = 1.
2
Compute:
1 2
- F (0, 0) = (1 + 1) = = 0.5 .
4 4
1 1
- F (0, 1) = 1 + e−2πi(1/2) = (1 + (−1)) = 0. 0 .
4 4
1
1 + e−2πi(1/2) = 0. 0 .
- F (1, 0) =
4
1 1 2
- F (1, 1) = 1 + e−2πi(1) = (1 + 1) = = 0.5 .
4 4 4
So:
F (0, 0) = 0.5, F (0, 1) = 0, F (1, 0) = 0, F (1, 1) = 0.5.
Q5. (Frequency-domain low-pass keeping only center)
Given (3×3) magnitude matrix
50 200 50
|F (u, v)| = 200 800 200 .
50 200 50
The low-pass described “keeps only the center component and zeros everything else.”
Interpreting “center” as the DC/zero-frequency term (after the usual FFT shift the DC is
centered), we keep a single value 800 at DC and zero elsewhere.
800 800
Inverse DFT with only DC = constant image where every spatial pixel equals = .
MN 9
800
Each spatial pixel = ≈ 88.8889.
9
(If instead the given matrix were not DC-centered, an index-shift would be required; the
result above follows the usual interpretation that the center entry is DC.)
Q6. (Derivative of Gaussian, σ = 1)
Formula: x2 + y 2
x
Gx (x, y) = − exp − .
2πσ 4 2σ 2
With σ = 1:
x 2 2
Gx (x, y) = − e−(x +y )/2 .
2π
3
Compute numerically:
1 −1/2
- Gx (1, 0) = − e ≈ −0.09653235263 ⇒ −0.0965 .
2π
2 −2 1
- Gx (2, 0) = − e = − e−2 ≈ −0.04307855860 ⇒ −0.0431 .
2π π
Q7. (Gradient magnitude & direction)
Given Ix = −12, Iy = 5.
Magnitude:
q p √ √
Ix2 + Iy2 = (−12)2 + 52 = 144 + 25 = 169 = 13 .
Direction (use atan2(Iy , Ix ) to get correct quadrant):
θ = atan2(5, −12).
Numeric:
θ ≈ 157.3801351◦ ⇒ 157.38◦ .
(Angle measured from positive x-axis; since Ix < 0 and Iy > 0, the vector lies in the second
quadrant.)
Q8. (Mean vs median filter)
Neighborhood:
0 0 255
N = 0 255 255 .
0 0 0
List the 9 values:
[0, 0, 255, 0, 255, 255, 0, 0, 0].
Sum = 255 + 255 + 255 = 765.
1. Mean filter output = 765/9 = 85. 85 .
2. Median filter output: sort the list:
[0, 0, 0, 0, 0, 0, 255, 255, 255].
Median (5th element) = 0. 0 .
4
3. Which is better for salt-and-pepper noise? Median filter is better — it rejects isolated
extreme pixels (salt or pepper) while mean averages them, producing residual bright/dark
bias.
End of answer key