You are on page 1of 2

Homework 2

Due by 03-04-2020 (11:59 PM)

Q.1. [8+7=15]
a) Write a MATLAB function ‘my2DConvolution’ for convolving a given grayscale image I with
a 2D convolution mask M. Your function should take care of the image boundary by mirroring the
image content appropriately. You cannot use the built in MATLAB functions like conv or conv2.
b) Convolve the given image using your function above with a 3x3 Gaussian mask.

Q.2. [5+5+5=15]
You can blur an image using a filter ‘B’ and find 𝑔𝑦 of an image using the filter ‘G’, where ‘B’ and
‘G’ are given as follows:

1/4 1/4
B=[ ]
1/4 1/4

−1 1
G= [ ]
−1 1

a) Are the above operations linear? If so, why?


b) You are asked to apply B to an image to generate a blurred image and then apply G to the
result to find the gradient of the blurred image. How would the output change if you apply G
first and then B?
c) If you are asked to apply one single filter S, instead of two filters in succession, how would
you find S?

Q.3. [5+5+5=15]
a) Write a function ‘my2DGaussian(S)’ to generate a 2D symmetric Gaussian blurring mask of a
given size ‘S’. You should appropriately normalize the mask before returning it to the user.
b) Using the function in Q.1. (a) and the filter in Q.3.(a) above, convolve the given image
‘pattern.tif’ with the following mask sizes: 9 × 9, 11 × 11, and 13 × 13. Display the original
image and all the blurred images in juxtaposition.
c) Give your analysis of the results in (b).

Q.4. [5+5+5+5+5=25]
a) Refer to figure 3.10(a) in your book. Using the coordinates (𝑟1 , 𝑠1 ) = (100,50) and (𝑟2 , 𝑠2 ) =
(200,230), give expression for the piecewise linear transform 𝑇(𝑟) to stretch the contrast of a
given grayscale image.
b) Write a MATLAB script to adjust contrast of the given image ‘pollen.png’ using the above
transformation.
c) Now use (𝑟1 , 𝑠1 ) = (𝑟𝑚𝑖𝑛 , 0) and (𝑟2 , 𝑠2 ) = (𝑟𝑚𝑎𝑥 , 255) to stretch contrast of the image.
d) Lastly, use histogram equalization to reset the contrast.
e) Show the results, i.e. the original image and the three contrast adjusted images in juxtaposition
and comment on your results.
Q.5. [5+5+2+3=15]
a) Write a MATLAB function ‘showImageBitPlanes()’ that would take an 8-bit grayscale image
along with the optional argument to show some specific bit-planes of the given image. If no
argument is specified, the function should return all bit-planes. Note: You are required to write
transformation relations of the bit-planes using the sample template ‘templateBitPlanes.m’.
b) Using only the two and four most significant bit-planes respectively, reconstruct the given
image ‘dollar.tif’ and save it as ‘reconstructedDollar2.tif’ and ‘reconstructedDollar4.tif’.
c) Display both the original and the reconstructed images in a single figure window.
d) Given the original and the reconstructed image above, compute the mean squared error (MSE)
and the peak signal-to-noise ratio (PSNR) using the following formulae:
𝑀 𝑁
1
𝑀𝑆𝐸(𝑓, 𝑔) = ∑ ∑(𝑓(𝑖, 𝑗) − 𝑔(𝑖, 𝑗))2
𝑀𝑁
𝑖=1 𝑗=1
2552
𝑃𝑆𝑁𝑅(𝑓, 𝑔) = 10𝑙𝑜𝑔10 ( )
𝑀𝑆𝐸(𝑓, 𝑔)
Q.6. [5+5+5=15]
Using the provided image ‘moon.tif’, do the following:
i) Compute the Laplacian of the image with 90-deg and 45-deg isotropic filters and display the
results with proper scaling.
ii) Sharpen the original image by using the outputs of part (i) above.
iii) Display the original as well as the sharpened images from part (ii) and comment on your
results.

Note: Submit your homework as a zip file at course email by the due date.
Don't forget to include the code as attachment.

You might also like