Professional Documents
Culture Documents
Sample Problem Set - SOLUTIONS: Fuv Fxye
Sample Problem Set - SOLUTIONS: Fuv Fxye
For reference, here are some important properties and equations (this will be provided):
M −1 N −1
F (u , v) = ∑ ∑ f ( x, y )e − j 2π (ux / M + vy / N ) (discrete)
Fourier transform =x 0=y 0
∞ ∞
F (u , v) = ∫ ∫ f ( x, y )e − j 2π (ux + vy ) dx dy (continuous)
−∞ −∞
1 M −1 N −1
Inverse Fourier
f ( x, y ) = ∑ ∑
MN =u 0=v 0
F (u , v) e j 2π (ux / M + vy / N ) (discrete)
transform ∞ ∞
f ( x, y ) = ∫ ∫ F (u , v)e j 2π (ux + vy ) du dv (continuous)
−∞ −∞
(impulse) δ ( x, y ) ⇔ 1
1
e −( x + y ) / 2σ ⇔ e − 2π σ (u + v )
2 2 2 2 2 2 2
(Gaussian)
Important Fourier pairs 2πσ 2
f ( x − x0 , y − y 0 ) ⇔ F (u , v) e − j 2π ( ux0 / M + vy0 / N )
Translation
F (u − u 0 , v − v0 ) ⇔ f ( x, y ) e j 2π ( u0 x / M + v0 y / N )
af ( x, y ) ⇔ aF (u , v)
Scaling 1
f (ax, by ) ⇔ F (u / a, v / b)
ab
x = r cos θ y = r sin θ u = r cos φ w = r cos φ
Rotation
f (r , θ + θ 0 ) ⇔ F (ω , φ + θ 0 )
Aθ B
Morphological erosion = {z } or A θ B
( B ) z ⊆ A= {z ( B ) z Ac ≠ ∅}
=
Morphological dilation A⊕ B {z ( Bˆ ) A ≠ ∅}
z
1
CSCI 510 / EENG 510
1. The image of stripes below on the left is too dark when displayed on a monitor. To
improve the display, we apply a gamma transformation to produce the image on the
right.
Sketch the gray level transformation for a gamma transformation that will produce the
image on the right.
Solution:
Gray level out
Gray level in
with s = cr γ and γ < 1
2. A digital camera captures a 400x400 pixel image of a black and white soccer ball on a
gray background. The ball is 30 cm in diameter and is 3 m away from the camera. The
camera has a field of field of 90 degrees horizontally and vertically.
Solution:
D/Z = d/f
2
CSCI 510 / EENG 510
image plane,
height h = 400
pixels
ball, D = 30 cm
f Z = 300
image of ball, d
pixels
(b) Give the histogram of the image, assuming that black, white, and gray pixels have the
gray levels 0, 255, and 128, respectively. Assume that there are an equal number of black
and white pixels on the ball.
Solution:
There are 400x400 = 160,000 total pixels.
The number of pixels on the ball is πr2 = (3.14)*(102) = 314.
There are 157 black (0) pixels, 157 white (255) pixels, and 160,000-314=159,686 gray (128)
pixels.
(c) A ping-pong (table tennis) ball is 40 mm in diameter. How far away must the ping-pong
ball be, to be exactly the same apparent size as the soccer ball in the image?
(i) 10 cm (ii) 0.4 m (iii) 0.75 m (iv) 1 m (v) 3 m
Solution:
Z = D f/d, where now D = 4 cm
So Z = (4 cm) (200 pix)/(20 pix) = 40 cm
3
CSCI 510 / EENG 510
3. A CCD camera has a image resolution of 2000 x 2000 pixels. The individual sensor
elements are squares measuring 10 x 10 um, with no spaces between them.
a. If the camera uses a lens with focal length = 100 mm, what is the field of view?
b. Assume the camera is mounted on an airplane, pointing straight down at the
ground. What height should the airplane fly, so that one pixel in the camera
corresponds to one meter on the ground?
Solution:
(a) The size of the image plane is 2000x10 um square. This is (2 x 10^3)(10 x 10^-6 m) = 20 x
10^-3 = 20 mm. The field of view is 2 atan(10 mm/100 mm) = 2 atan(0.1) = 2 (5.7) = 11.4
degrees.
(b) If one pixel is one meter, then the entire image covers 2000x2000 meters. f/w = H/W
(100 mm)/(20 mm) = H/(2000 m)
or H = 10000 m
Solution:
s H(s)
0 0
1 2000
4
CSCI 510 / EENG 510
2 0
3 2000
4 2000
5 0
6 3000
7 1000
corr(r,c) = score;
end
end
Solution:
corr = zeros(100); % resulting correlation image
for r=1:90
for c=1:90
score = 0;
for m=1:10
for n=1:10
score = score + I(r+m, c+n) * T(m,n);
end
end
corr(r,c) = score;
end
end
Note that the above assumes that the origin of the template is at the top left corner; i.e., T(1,1). If the origin of the template is in
the middle you could do
score = 0;
for m=-4:5
5
CSCI 510 / EENG 510
for n=-4:5
score = score + I(r+m, c+n) * T(m+5,n+5);
end
end
corr(r,c) = score;
end
end
6. Compute the convolution of the following image with the filter w (assume that the
origin of w is at its center). To compute the result at the border, pad the image with
zeros.
−1 −1 −1
w = 0 0 0
1 1 1
Image:
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 10 10 10 10 0 0
0 0 10 10 10 10 0 0
0 0 10 10 10 10 0 0
0 0 10 10 10 10 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
Result:
6
CSCI 510 / EENG 510
Solution:
For convolution we have to rotate w by 180° and then do the sum of products at each position.
0 0 0 0 0 0 0 0
0 - - - - - - 0
10 20 30 30 20 10
0 - - - - - - 0
10 20 30 30 20 10
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 10 20 30 30 20 10 0
0 10 20 30 30 20 10 0
0 0 0 0 0 0 0 0
7. Consider a 3x3 spatial mask that averages the four closest neighbors of a point (x,y) but
excludes the point itself from the average. Find the equivalent filter, H(u,v) in the
frequency domain. (Hint: Use the translation property of the Fourier transform).
Solution:
You can see that this acts like a low pass filter. At (u,v)=(0,0), H(u,v)=1. The values of H(u,v)
decrease as (u,v) move away from the origin.
Although you wouldn’t need to implement Matlab code on an exam, we can plot the magnitude
of H:
7
CSCI 510 / EENG 510
0.8
0.6
0.4
0.2
0
150
100
50 100
80
60
40
0 20
0
At very high frequencies (where both u and v are high), the magnitude of H starts to rise again,
so it does not attenuate those high frequencies like a low pass filter should.
M = 100;
N = 100;
What would H(u,v) look like for a 3x3 box averaging filter?
8. You want to apply the Laplacian of a Gaussian edge operator, ∇ G to an image f(x, y)
2
of size 512x512. Assume that the edge operator is of size 32x32, and that its origin is at
its center. Describe in words how to perform this in the frequency domain.
Solution:
1. Create the 32x32 edge operator in the spatial domain, and zero pad it to size 512x512.
8
CSCI 510 / EENG 510
9. Describe the Fourier transform of a filter that performs smoothing with the ideal low
pass filter, followed by differentiation in the x direction. Sketch a plot of its magnitude.
Notes: The Fourier transform of the ideal low pass filter is:
1 u 2 + v 2 ≤ R 2
H (u , v ) =
0 u + v > R
2 2 2
∂x n
Solution:
Convolution in the spatial domain is equivalent to multiplication in the frequency domain.
The resulting filter is
j 2π u u 2 + v 2 ≤ R 2
H ( u, v ) =
0 u 2 + v2 > R2
Here is the x-derivative filter and the ideal low pass filter:
9
CSCI 510 / EENG 510
Here is the combined filter, obtained by point by point multiplication (zoomed in). Also show in
3D.
Here is “moon” image, and the results of applying the combined filter:
10
CSCI 510 / EENG 510
11
CSCI 510 / EENG 510
FLP(v,u) = 1;
else
FLP(v,u) = 0;
end
end
end
figure, imshow(abs(FLP),[]);
10. Assume that the 2D Fourier transform of the MxN image f(x,y) is F(u,v). Determine
the 2D Fourier transform of the following functions. You may wish to refer to the
properties of the Fourier transform in the table on the front page.
a. 4 f(2x - 4, y + 2)
(select one)
(i) 2e − j 2π (2u / M − 2 v / N ) F (u / 2, v)
(ii) 4e − j 2π (2u / M −v / N ) F (u / 2, v)
(iii) 2e − j 2π (4u / M − 2 v / N ) F (u / 2, v / 2)
(iv) 4e − j 2π ( u / M −2 v / N ) F (u, v / 2)
Solution: This function involves both translation and scaling. First define a function f1(x,y):
f1 ( x, y ) = f ( x − 4, y + 2)
Its Fourier transform is
F1 (u, v ) = e − j 2π ( 4 u / M −2 v / N ) F (u, v )
Now define
f 2 ( x, y=
) 4 f1 (2 x, y=
) 4 f (2 x − 4, y + 2) 1
Its Fourier transform is
1
F2 (u, v ) = 4 ⋅ F1 (u / 2, v ) = 2e − j 2π ( 2 u / M −2 v / N ) F (u / 2, v )
2
1
This step may be a little tricky to follow. Let’s take a simpler example: f(x) = x^2. Define f1(x) = f(x-4)=(x-4)^2.
Then define f2(x) = f1(2x). You substitute 2x in place of x in the expression for f1, to get f2(x)=(2x-4)^2.
12
CSCI 510 / EENG 510
Or, you could do the scaling first and then the translation. Define function f1(x,y):
f1 ( x, y ) = 4 f (2 x, y )
Its Fourier transform is
F1 (u , v) = 2 F (u / 2, v)
Now define
f 2 ( x, y )= f1 ( x − 2, y + 2)= 2 f ( 2 ( x − 2 ) , y + 2 )
Its Fourier transform is
− j 2π (2 u / M − 2 v / N )
=F2 (u , v) F=
1 (u , v )e 2 F (u / 2, v)e − j 2π (2u / M − 2 v / N )
(select one)
(i) e j 2π ( v / N ) F (u , v)
(ii) F 2 (u , v)
(iii) e j 2π (u / M − 2 v / N ) F 2 (u , v)
(iv) e j 2π (2 v / N ) F 2 (u , v)
Solution:
f ( x − 3, y + 2) ⇔ e − j 2π ( 3u / M −2 v / N ) F (u, v )
f ( x + 3, y ) ⇔ e j 2π ( 3u / M ) F (u, v )
Thus
f ( x − 3, y + 2) ∗ f ( x + 3, y ) ⇔ e − j 2π ( 3u / M −2 v / N ) e j 2π ( 3u / M ) F (u, v ) F (u, v )
= e j 2π ( 2 v / N ) F 2 ( u , v )
.
11. The following is a binary image I and a structuring element S. Assume that the origin
of S lies at its center.
13
CSCI 510 / EENG 510
I: S:
0 1 2 3 4 5 6 7 8 9
0
1
2 1 1 1 1 1 1
3 1 1 1 1 1
4 1 1 1 1 1 1 1 1
5 1 1 1 1 1 1 1
6 1 1 1 1 1 1
7 1 1 1 1 1 1
8
9
0 1 2 3 4 5 6 7 8 9
0
1 1 1 1 1 1 1
2 1 1 1 1 1 1 1 1
3 1 1 1 1 1 1 1
4 1 1 1 1 1 1 1 1
5 1 1 1 1 1 1 1 1
6 1 1 1 1 1 1 1 1
7 1 1 1 1 1 1 1 1
8 1 1 1 1 1 1
9
14
CSCI 510 / EENG 510
0 1 2 3 4 5 6 7 8 9
0
1
2
3 1
4 1
5 1 1 1
6 1 1 1 1
7
8
9
12. A small portion of a binary image I is shown below. Assume that you want to join the
two groups of 1’s into a single connected group, while distorting the overall image as
little as possible (this might be from an image of a fingerprint, for example).
a. Using the structuring element S shown below, would you use morphological
opening or morphological closing?
b. Apply the operation you selected in (a) to the image I. (Assume that there are
0’s outside the border of the image.) Show the intermediate results of dilation
and erosion (or vice versa).
I:
1 1
1 1 1
1 1 1
1 1 1
1 1 1
1
1 1
1 1
Solution:
We would do a morphological closing, which is a dilation followed by an erosion.
15
CSCI 510 / EENG 510
The dilation of I by S is shown below. It consists of all the original 1’s, plus some new 1’s.
Bold (and red) indicate the new 1’s.
1 1
1 1 1
1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1
1 1 1 1
1 1
The erosion of the above by S is shown below. It is the same as the original except that there is
an additional “1” joining the two groups, and we have lost the 1’s on the rightmost column
because of the assumption that there were 0’s beyond the border.
1
1 1
1 1 1
1 1 1 1
1 1 1
1
13. A camera takes images of a test pattern. The image is converted to binary, as shown in
the left image. Occasionally, diagonal streaks appear in the image due to some
unknown noise process, as shown in the right image. To help diagnose the problem, we
want to create an algorithm that will automatically count the streaks. It is observed
that the streaks are always at the same angle (45 degrees), between 35 and 50 pixels
long, and between 2 and 4 pixels wide. Describe an algorithm, based on morphological
processing, that will automatically count the streaks. (Be as specific as possible!)
16
CSCI 510 / EENG 510
Solution: We assume that there are no structures in the image (other than the noise stripes) that
are longer than 35 pixels. We create a structuring element that is a line at 45 degrees, 35 pixels
long, and 2 pixels wide (ie, the minimum size). We “open” the image with this structuring
element (“imopen” in Matlab), and then use a connected component labeling algorithm
(“bwlabel” in Matlab) to count the objects. An opened image is shown below.
Actually, if all you want to do is to count the streaks (instead of producing an image of the
streaks), you can simply erode the original image with the line structuring element, and count the
number of connected components.
Finally, note the extra blob on the right hand side of the image. This is due to the fact that when
you erode, the image is effectively padded with 1’s outside the boundary. So the line actually
fits partially inside the white area at the right edge, with the remainder falling outside in the 1’s.
17
CSCI 510 / EENG 510
14. Explain why the edges found by the Laplacian of a Gaussian edge operator form closed
contours.
Solution:
The edges are the zero crossings of the values resulting from convolving the image with the
Laplacian of Gaussian operator. In other words, the edges are the boundary between regions
with negative values and regions with positive values. Those regions are connected components.
A contour surrounding a connected component must be a closed path.
18