Professional Documents
Culture Documents
ProblemSet01 Solution PDF
ProblemSet01 Solution PDF
ProblemSet01 Solution PDF
1. This problem is to install Python and setup dippykit library on your machine
(a) On your browser, go to dippykkit webpage
(b) Install Python 3 and Pycharm IDE on your machine by following the in-
structions under Setting Up the Environment. Make sure you select the
checkbox for adding Python to the path if you’re an installation wizard
(c) Launch PyCharm and create a new project named dippykit. Set up the
interpreter by following the instructions under Creating a New PyCharm
Project
(d) In PyCharm, press CTRL+SHIFT+A to get the command search option, and
type terminal and hit enter to go the terminal. This will launch the terminal
that we will use to install the library
(e) Check that you have Python 3 installed correctly by typing python in the
terminal. If you get the python interactive prompt (>>>) and python ver-
sion is 3.x.x (e.g., 3.7.0), then python was correctly installed. Type exit()
to go back to the terminal.
(f) Install dippykit by typing pip install dippykit in the terminal
(g) Verify your installation by following the steps under Verifying Your In-
stallation
2.* This problem is to get you familiar with some of the basic image processing
functions in dippykit library. The link to the image used in this exercise can be
found on the course website in Tentative Course Schedule and Timeline
table under Course Materials.
(a) Launch PyCharm IDE and create a new python file
(b) In the python file, import dippykit, and numpy libraries
import dippykit as dip
import numpy as np
(c) Use the function im read to read the image in Python and save it as a
variable X.
X = dip.im_read("images/cameraman.tif")
The image values will be normalized to be in the range [0, 1]. Multiply the
image by 255 to get the values into the range [0, 255] as a floating point
X *=255
(e) Add a constant value of 75 to every pixel in X and save the resulting image
as a variable Y
Y = X + 75
(g) Use the function dip.im write to save Y as an image file on your hard drive.
dip.im_write(Y,"cameraman_add.tif")
Include this image in your solution. Write your observations on the resulting
image.
(h) Square the intensity value of every pixel in X and save it as a variable Z. Use
the function im write to save the resulting image as an image file on your
hard drive. Include this image in your solution. Write your observations on
the resulting image.
Z = X**2
Z = dip.float_to_im(Z/255)
dip.im_write(Z,"cameraman_square.tif")
(i) Compute the Fourier Transform of the image X using the dip.fft2 func-
tion. In order to show the resulting Fourier Transform properly, use the
dip.fftshift function, and np.log function to reduce the dynamic range.
fX = dip.fft2(X)
fX = dip.fftshift(fX)
fX = np.log(np.abs(fX))
Solution:
The solution di↵ers based on the selected image. The steps are straightfor-
ward. See Python code: ch01 basic image manipulations
3.* This problem is to refresh your memory from the 1D discrete signal processing
class. Given a discrete signal x[n] = [1, 1, 3, 5, 3, 1, 1] and two systems with
impulse responses h1 [n] = [1, 1] and h2 [n] = [ 2, 1], answer the following
questions.
(a) What is the length of the signal y1 [n]? (i.e. the output of the parallel system
shown in Fig. 1(a)). Explain.
(b) What is the length of the signal y2 [n]? (i.e. the output of the cascade system
shown in Fig. 1(b)). Explain.
ώкͼϔͽ
ώлͼϔͽ
(c) Find y1 [n] and y2 [n]. You can write both outputs in the same way you are
given the input signals above or you can plot them.
Solution:
(a) The parallel system can be seen as one system with an impulse response
hp [m, n] = h1 [m, n] + h2 [m, n] = [ 1, 2].
The length of x[m, n] is 7 points and the length of hp [m, n] is 2 points. Then,
y1 [m, n] will have 7 + 2 1 = 8 points.
(b) The cascade system can be seen as one system with an impulse response
hc [m, n] = h1 [m, n] ⇤ h2 [m, n] which has a length of 2 + 2 1 = 3 points.
The length of x[m, n] is 7 points and the length of hc [m, n] is 3 points. Then,
y1 [m, n] will have 7 + 3 1 = 9 points.
n1
Solution:
5 3
(a) The first periodicity matrix: N1 =
1 4
5 2
(b) The second periodicity matrix: N2 =
1 5
(c)
|det(N1 )| = |5 ⇥ 4 ( 3) ⇥ 1| = 23
|det(N2 )| = |5 ⇥ 5 2| = 23
As shown above, |det(N1 )| = |det(N2 )|. Other periodicity matrices will be
also considered correct with the same absolute value of determinant 23.
5.* Consider the 3 ⇥ 3 2-D linear, shift-invariant filter whose impulse response is
8
>
> 2 m = 0, n = 1 2 3
>
>
< 2 m = 0, n = 1 1 2 1
h[m, n] = 1 m = ±1, n = 1 or h=4 0 0 0 5
>
> 1 m = ±1, n = 1 1 2 1
>
>
: 0, otherwise
(a) This filter is separable! Explain why by giving the two 1-D components that
make up the 2-D filter.
(b) Determine the frequency response of this filter. Exploit the separable form
of h[m, n]. Give an analytic formula and also give a sketch of a contour plot
for the magnitude of the frequency response.
(c) If the input to the filter is the 7 ⇥ 7 “image” below, determine the output.
0 0 0 1 1 1 1
0 0 0 1 1 1 1
0 0 0 1 1 1 1
0 0 0 1 1 1 1
1 1 1 0 0 0 0
1 1 1 0 0 0 0
1 1 1 0 0 0 0
Show how to take advantage of the separable nature of the impulse response.
(d) Give a verbal description of what this filter does, i.e. highpass, lowpass, etc.
Solution:
(a) One could show the filter is separable with
) 32
h1 [m] = [1, 2, 1] ⇥ ⇤ 1
) 1 2 1 ⇤ 4 0 5 = h[m, n]
h2 [n] = [1, 0, 1]T 1
(c) The convolution of the input signal g[m, n] and the separable filter can be
calculated by convolving it with h1 [m], then with h2 [n]:
f [m, n] = g[m, n] ⇤ h[m, n] = g[m, n] ⇤ h1 [m, n] ⇤ h2 [m, n]
2 3 2 3
0 0 0 1 1 1 1 0 0 0 1 3 4 4 3 1
6 0 0 0 1 1 1 17 2 3 60 6 0 0 1 3 4 4 3 17 2 3
6 7 7
6 0 0 0 1 1 1 17 ⇥ ⇤ 1 60 0 0 1 3 4 4 3 17 1
6 7 6 7
= 6 0 0 0 1 1 1 17 ⇤ 1 2 1 ⇤ 4 0 5 = 6 0 0 0 1 3 4 4 3 17 ⇤ 4 0 5
6 1 1 1 0 0 0 07 1 61 3 4 3 1 0 0 0 07 1
6 7 6 7
4 1 1 1 0 0 0 05 41 3 4 3 1 0 0 0 05
1 1 1 0 0 0 0 1 3 4 3 1 0 0 0 0
2 3
0 0 0 1 3 4 4 3 1
60 0 0 1 3 4 4 3 17
6 7
60 0 0 0 0 0 0 0 07
6 7
60 0 0 0 0 0 0 0 07
6 7
=6 1 3 4 2 2 4 4 3 17
61 3 4 2 2 4 4 3 17
6 7
60 0 0 0 0 0 0 0 07
6 7
4 1 3 4 3 1 0 0 0 05
1 3 4 3 1 0 0 0 0
Determine one possible choice for h[m, n] (i.e. find all possible values for a, b and
c). Hint: Use the definition of the 2-D frequency response. Assume h[m, n] is
3 ⇥ 3 and symmetric.
c b c
b a b
c b c
h[m,n]
10. Given a filter, h[m,n], with the impulse response depicted in Fig. 7. All samples
that are not shown assume the value of zero.
(a) Show that this filter is separable.
(b) Assume we used this filter on an image, f[m,n], and we obtained the output,
y[m,n], shown in Fig. 8. Find the values of [m,n] where the image f[m,n] has
non-zero values. Present this answer via a sketch in the [m,n] plane.
n
depicted in h[m,n]
. All samples that are not shown assume
1 2 1
], and
0 0 0
] where
m
Present this -1 -2 -1
n y[m,n]
0 3 6 3 0
2 6 8 6 2
1 0 -2 0 1
-2 -6 -8 -6 -2
m
-1 -3 -4 -3 -1