Course Title: Introduction to Image Processing
Course Instructor(s): Semester: Fall 2022
Dr Muhammad Zubair, Awais Lodhi
Course Code: Marks: 100
Duration : 150 minutes Time:
Date : Program: BSCS
Paper Review (Date & Time):
Instructions
· Attempt all questions in sequence.
· Start each question on a new page and attempt all parts of the question together
· Avoid using extra sheet.
· Answer all questions in context of class discussions.
· State all your assumptions clearly.
· This is a Closed Book & Notes Exam, No Cheet Sheet is allowed.
· Use of Electronic Gadgets other than Calculators (Laptops, Mobiles, Smart
Watches etc.) is not allowed.
· Exchange of calculators is not allowed.
· Please use only blue and/or black ink to solve the paper. Pencil is allowed for
figures and diagrams only. Using any other color (Red, Green Pink, Orange,
Purple etc) will result in 0 marks for the whole paper.
· All indexing conventions is from Python.
Name:____________________ Roll#: _____________________
1. Please describe the project and explain the process step by step as pseudo-code. What was your
contribution in the project. (5 Marks)
2. Consider the following image matrix (assume 8 bpp): (5+5 =10)
0 1 2 3 4
0 13 218 254 131 110
1 24 253 203 148 114
2 39 29 239 165 236
3 6 1 131 192 17
4 24 242 38 14 195
a) Show output image if the following function is applied?
2𝑥 𝑥 ≤ 100
𝑓 𝑥 = 𝑥 100 > 𝑥 ≤ 180
0.5𝑥 𝑥 > 180
b) Apply 3x3 box filter on position (0, 0), (4,1) & (3,2). Use zero padding where required.
Introduction to Image Processing Page: 1
3. Consider the following inverted black & white image (5+5 =10)
a) Describe some morphological technique so that only the horizontal lines remain in the image. (You
need to tell the technique as well as the appropriate structuring element)
b) Describe some morphological technique so that only the diagonal lines disappear from the image.
(You need to tell the technique as well as the appropriate structuring element)
Hint:
i. The lines are black and background is white.
ii. The thickness of each line is 1 pixel.
4. The Hole Filling Morphological Algorithm is given below. Apply it and show result after each iteration on the
given image.
𝑋 𝑘+1 = 𝑋𝑘 ⊕ B ∩ 𝐼𝑐
where Xk is the currently filled hole. B is the structuring element and Ic is the complement of the image. Stop
when Xk = Xk-1. X0 = img(4,7) (10 Marks)
0 1 2 3 4 5 6 7 8 9
0 0 0 0 0 0 0 0 0 0 0
1 0 0 1 1 0 0 0 0 0 0
0 1 0
2 0 1 0 0 1 1 1 1 0 0
1 1 1
3 0 1 0 0 0 0 0 0 1 0
0 1 0
4 0 1 0 0 1 1 0 0 1 0
SE
5 0 1 1 1 0 0 1 1 0 0
6 0 0 0 0 0 0 0 0 0 0
5. Consider the following 8 bit color image: (5+5+5+5=20)
0 1 2 3 4 0 1 2 3 4 0 1 2 3 4
0 253 8 160 123 153 0 170 188 73 237 127 0 70 147 20 174 8
1 207 98 184 189 217 1 23 96 203 169 15 1 110 148 17 181 110
2 169 253 225 199 146 2 28 51 190 240 3 2 10 32 186 87 19
3 118 129 9 233 77 3 141 183 140 193 153 3 65 250 139 174 89
4 158 109 215 104 220 4 180 194 117 179 107 4 233 205 98 232 23
R G B
a) Find the gray image using the formula.
1
𝑖𝑚𝑔 𝑔 =3 𝑖𝑚𝑔 𝑟 + 𝑖𝑚𝑔 𝑔 + 𝑖𝑚𝑔 𝑏
b) Apply sobel horizontal edge detection on (4,4), (1, 4), (2, 3) on the gray image from a. Use Zero padding
if required.
c) Apply sobel vertical edge detection on (0,0), (2, 4) on each R, G, B channels. Use White padding if
required.
d) Convert points (1, 2) and (4, 0) to CMYK model?
Introduction to Image Processing Page: 2
6. Consider the following 8 bit image (10 + 5 + 5 = 20)
0 1 2 3 4
0 98 199 170 203 129
1 253 233 23 190 109
2 129 104 28 140 160
3 109 153 141 117 184
a. Compute fft for positions (0, 0) , (1,0) and (2, 3)
b. The first value extracted after applying IDFT is the average of all the frequencies present in the
image. Do you agree? Argue your answer.
c. Apply FFT shift on this image.
7. Identify noise models from the following histograms. (5 Marks)
(a) (b) (c)
8. What techniques can be used to remove the following noise types from the image. Also give examples for
each case. (5 Marks)
a. Salt & Pepper Noise
b. Uniform Noise
9. An image was distorted by the following noise pattern. Draw the approximate FFT you expect to see after
taking 2D transform. How do you propose to resolve the problem? (5 Marks)
10. Write a Python or Matlab function named weighted_gray_or_negative that receives file name as parameter.
It opens the file, if it is a color image it converts it into grayscale using the formula below and returns the
grayscale image. If it is already a grayscale image, its negative image is returned. (10 Marks)
𝑖𝑚𝑔 𝑔 = 0.299 ∗ 𝑖𝑚𝑔 𝑟 + 0.587 ∗ 𝑖𝑚𝑔 𝑔 + 0.114 ∗ 𝑖𝑚𝑔 𝑔
~~~~~~~~~~~~~~~~Best of Luck~~~~~~~~~~~~~~~~
Introduction to Image Processing Page: 3
Formula Sheet
Sobel Operators
-1 0 1 1 2 1
-2 0 2 0 0 0
-1 0 1 -1 -2 -1
Gx Gy
Gaussian Kernel (3x3)
1/16 2/16 1/16
2/16 4/16 2/16
1/16 2/16 1/16
Box Kernel (3x3)
1/9 1/9 1/9
1/9 1/9 1/9
1/9 1/9 1/9
Fourier Transform
∞
𝐹 𝑢 = 𝑓 𝑥 𝑒 −2𝑗𝜋𝑢𝑥
−∞
Inverse Fourier Transform
∞
𝑓 𝑥 = 𝐹 𝑢 𝑒 2𝑗𝜋𝑢𝑥
−∞
2D Discrete Fourier Transform
𝑁−1 𝑀−1
𝑢𝑥 𝑣𝑦
−2𝑗𝜋 +
𝐹 𝑢,𝑣 = 𝑓 𝑥,𝑦 𝑒 𝑁 𝑀
𝑥=0 𝑦=0
2D Inverse Discrete Fourier Transform
𝑁−1 𝑀−1
𝑢𝑥 𝑣𝑦
1 2𝑗𝜋 +
𝑁 𝑀
𝑓 𝑥,𝑦 = 𝐹 𝑢,𝑣 𝑒
𝑀𝑁
𝑢=0 𝑣=0
Euler Identity
𝑒 𝑗𝜃 = 𝑐𝑜𝑠 𝜃 + 𝑗𝑠𝑖𝑛 𝜃
𝑒 −𝑗𝜃 = 𝑐𝑜𝑠 𝜃 −𝑗𝑠𝑖𝑛 𝜃
Introduction to Image Processing Page: 4