ProblemSet01 Solution PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

GEORGIA INSTITUTE OF TECHNOLOGY

ECE 6258: Digital Image Processing

Solution of Problem Set #01

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")

(d) Convert the image array to normalized floating point space


X = dip.im_to_float(X)

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

(f) Renormalize the image and convert it to integer space


Y = dip.float_to_im(Y/255)

(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))

(j) Use the function dip.imshow to show the resulting spectrum.


dip.imshow(fX)
dip.show()

Save the figure and include it in your solution.

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.

ώкͼϔͽ

Ϟͼϔͽ ϟкͼϔͽ Ϟͼϔͽ ώкͼϔͽ ώлͼϔͽ ϟлͼϔͽ

ώлͼϔͽ

(a) Parallel system (b) Cascade system

Figure 1: Parallel System and Cascade System

(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.

(c) y1 [n] = [ 1, 3, 5, 11, 13, 7, 3, 2]


y2 [n] = [ 2, 1, 4, 6, 2, 6, 2, 2, 1]
4.* (a) Determine a periodicity matrix that describes the periodicity of the array
shown in Fig. 2, where the filled circles have a value of one and the dots
have a value of zero.
n2

n1

Figure 2: A periodic two-dimensional sequence

(b) Determine a second periodicity matrix for this array.


(c) Show that the absolute values of the determinants of these two matrices are
equal.

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

(b) Since, h[m, n] = h1 [m] ⇤ h2 [n], then:


H(µ, ⌫) = H1 (µ) · H2 (⌫)
= (2 + 2 cos(2⇡µ)) ( 2j sin(2⇡⌫))
= 4j [1 + cos(2⇡µ)] sin(2⇡⌫)

(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

(d) The filter is low-pass in µ and band-pass in ⌫. See Fig. 3.


(a) Plot of H1 (µ) (b) Plot of H2 (⌫)

(c) Plot of |H(µ, ⌫)|

Figure 3: Magnitude spectra of the filters

Python code: ch02 seperable signal frequency response


6. Compute the impulse response h[m, n] of the ideal lowpass filter for which one
period of the frequency response is shown in Fig. 4. The response is one in the
shaded regions and zero in the unshaded ones.

Figure 4: H(u, v).


7. We saw in class that a separable linear, shift-invariant system could be imple-
mented more efficiently than a normal LSI system. A similar savings can be
realized in a general LSI system when the input is also a separable signal. In
this problem you will derive an even more efficient implementation that can be
used to compute the output of a separable system when the input is a separable
sequence. Let the input to the system be the sequence f [m, n] = f1 [m]f2 [n]
where 0  m  N1 1 and 0  n  N2 1 and let the impulse response of the
system be h[m, n] = h1 [m]h2 [n] where 0  m  M1 1 and 0  n  M2 1.
(a) Derive a procedure for calculating the system output using only 1-D con-
volutions. You should be able to find a procedure that requires only two
convolutions plus some auxilliary calculations.
(b) Calculate the total number of multiplications required if N1 = N2 = 500
and M1 = M2 = 15. Compare this value with the number of multiplications
required in the general case and when just the separability of the system is
exploited.
8.* Consider the sequence f defined by

1, 0  m  n
f [m, n] =
0, otherwise.
Determine the convolution of f with itself.
Verify your answer using Python.
Solution:
f [m, n] and its shifted-mirrored version, f [k m, l n], will overlap only in the
region where 0  m  n. The geometric shape of the overlap is a parallelogram
with an area of (m + 1) ⇥ (n m + 1) as shown in Figure 5. (The illustrations in
Figure 5 show the functions as continuous instead of discrete. Please use them
as a guide to describe the regions of interest in discrete domain.)
From the above, we can obtain the expression of g[m, n] as:

(m + 1) ⇥ (n m + 1), n m 0
g[m, n] =
0 , otherwise.

Fig. 6 shows g[m, n] via Python .


Python code: ch02 conv2d of same signal

(a) Plot of f [k, l] (b) Plot of f [m k, n l] (c) Overlay of f [m k, n l]andf [k, l]

Figure 5: f [m, n] and its shifted-mirrored version, f [k m, l n]


Figure 6: Plot of g[m, n] = f [m, n] ⇤ f [m, n]
9. We wish to design a simple 3 ⇥ 3 lowpass filter that satisfies the following con-
ditions:
8
< 1, (u, v) = (0, 0)
H(u, v) = 0, (u, v) = (0.5, 0), (0.5, 0.5), (0, 0.5), ( 0.5, 0.5),
:
( 0.5, 0), ( 0.5, 0.5), (0, 0.5), and (0.5, 0.5)

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

Figure 7: Plot of h[m, n]

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

Figure 8: Plot of y[m, n]

You might also like