## Description

1. (20 points.) First, write a few functions that will help with the rest of the homework. Turn in your code listings foreachfunction. Eachfunctionshouldonlybeacouplelineslong.

(a) (5 points.) A function called fftshow that displays the log of the magnitude of the 2-D DFT of an image andplotsitsothattheDCelementisatthecenterofthefrequency-domainimage,andtheresultisscaled tousethefullgrayscalerange. Usethefunctions fft2 and fftshift. (b) (5 points.) A function called boxfilt that takes as input a grayscale image im, an odd box width w and an odd box heighth, and returns an ideal low-pass box frequency-domain ﬁlter the same size as im that that passes the w frequencies around DC along the columns of the image and the h frequencies around DCalongtherowsoftheimage. TheDCelementshouldbeattheupperleftcorneroftheoutput. Youcan assumetheimagealsohasodddimensions. (c) (5 points.) A function called freqflt that applies a frequency-domain ﬁlter to an image by multiplying the ﬁlter with the image’s 2D DFT, taking the inverse 2D DFT, and returning the real part of the result as a uint8. Thefunctionshouldassumethatthefrequency-domainﬁlterhasthesamesizeastheinputimage. Notethereisafunctioncalled ifftshift thatmovestheDCelementbacktotheupperleftcorner,ifyou needit. (d) (5 points.) A function called gaussfilt that takes as input a grayscale image im and a 2×2 covariance matrixC.Theﬁltershouldreturnalow-passfrequency-domainGaussianﬁlterthesamesizeasimcentered atDCwiththegivencovariancematrix. Thisone’salittletricky. Remembertheformulafora2DGaussian distribution (e.g., equation 2-123), and how you used meshgrid to construct a related image in HW 1. We wantthemaximumelementoftheﬁltertobe1,soyouonlyneedtoworryabouttheexp(···)part,notthe scalingfactorinfront. Asabove,theDCelementshouldbeattheupperleftcorneroftheoutput.

2. (30points.) Considertheinputimagetiger.png. Ineachofthefollowingsubproblems,providearesult(either in the spatial domain or frequency domain as indicated) and explain why the result looks the way it does. For frequency-domainresults,use fftshift tomakesureDCisinthemiddleoftheimageforeasiervisualization.

(a) (4points.) Use fftshow todisplaythe2DDFToftheimage. (b) (4 points.) Construct a box ﬁlter with [w,h] = [31, 31]. Look at it in the frequency domain with fftshift. (c) (4 points.) Apply the above box ﬁlter to the input image. What does the result look like in the spatial domain? (d) (4 points.) Construct a box ﬁlter with [w,h] = [91, 91]. Look at it in the frequency domain with fftshift,andapplyittotheinputimage. Howdoestheoutputimagedifferfrompart(c)? (e) (4 points.) Construct a box ﬁlter with [w,h] = [91, 31] and apply it to the input image. How does the resultdifferfromparts(c)and(d)? (f) (5 points.) Construct a box ﬁlter with [w,h] = [91, 399] and apply it to the input image. What is the interpretationofthisﬁlter? Howdoestheresultdifferfrompart(e)? (g) (5 points.) Construct a box ﬁlter with [w,h] = [599, 31] and apply it to the input image. What is the interpretationofthisﬁlter? Howdoestheresultdifferfrompart(e)? Morefunonthenextpage−→

3. (30 points.) We’ll again consider the input image tiger.png, but now look at the results of Gaussian ﬁltering instead of box ﬁltering. In each of the following subproblems, provide a result (either in the spatial domain or frequencydomainasindicated)andexplainwhytheresultlooksthewayitdoes. (a) (4 points.) Construct a Gaussian ﬁlter using gaussfilt with C =· 100 0 0 100 ¸and look at it in the frequencydomainwith fftshift. HowdoesitcomparetotheboxﬁlterinProblem2b? (b) (4 points.) Apply the above Gaussian ﬁlter to the input image. What does the result look like in the spatial domain? (c) (4points.) Whatdoestheaboveresultlooklikeinthefrequencydomain? (d) (4 points.) Construct a Gaussian ﬁlter using gaussfilt with C =· 900 0 0 900 ¸and apply it to the input image. Howdoestheresultdifferfrompart(b)? (e) (4 points.) Construct a Gaussian ﬁlter using gaussfilt with C =· 900 0 0 100 ¸and apply it to the input image. Explaintheresults. (f) (5 points.) Now let R =· cos30◦ −sin30◦ sin30◦ cos30◦ ¸and D =· 900 0 0 100 ¸. Construct a Gaussian ﬁlter using gaussfilt withC =R>DR. Whatdoesthisﬁlterlooklikeinthefrequencydomain? (g) (5points.) Whatistheresultofapplyingthisﬁltertotheinputimage? Carefullyexplaintheresults.

4. (20points.) Considerthehigh-boostspatial-domainﬁltergivenby 1 16

−1 −2 −1 −2 28 −2 −1 −2 −1

. (a) (5points.) InMatlab,displaythemagnitudeofthe2D256×256DFTofthisﬁlter,centeringsotheDCterm isatthecenteroftheimage. Interpretwhatyousee. (b) (5points.) Applytheﬁltertotheimage tiger.png andverifythatthisisindeedanedge-enhancingﬁlter. (c) (10 points.) With paper and pencil, explicitly compute the frequency response H(u,v) of the high-boost ﬁlter. Youshouldgetaclosed-formanswerinvolvingtrigfunctions.