ECSE4540 Homework#4 solution

$29.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (4 votes)

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 filter 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 filter to an image by multiplying the filter with the image’s 2D DFT, taking the inverse 2D DFT, and returning the real part of the result as a uint8. Thefunctionshouldassumethatthefrequency-domainfilterhasthesamesizeastheinputimage. 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.Thefiltershouldreturnalow-passfrequency-domainGaussianfilterthesamesizeasimcentered atDCwiththegivencovariancematrix. Thisone’salittletricky. Remembertheformulafora2DGaussian distribution (e.g., equation 2-123), and how you used meshgrid to construct a related image in HW 1. We wantthemaximumelementofthefiltertobe1,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 filter with [w,h] = [31, 31]. Look at it in the frequency domain with fftshift. (c) (4 points.) Apply the above box filter to the input image. What does the result look like in the spatial domain? (d) (4 points.) Construct a box filter with [w,h] = [91, 91]. Look at it in the frequency domain with fftshift,andapplyittotheinputimage. Howdoestheoutputimagedifferfrompart(c)? (e) (4 points.) Construct a box filter 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 filter with [w,h] = [91, 399] and apply it to the input image. What is the interpretationofthisfilter? Howdoestheresultdifferfrompart(e)? (g) (5 points.) Construct a box filter with [w,h] = [599, 31] and apply it to the input image. What is the interpretationofthisfilter? Howdoestheresultdifferfrompart(e)? Morefunonthenextpage−→
3. (30 points.) We’ll again consider the input image tiger.png, but now look at the results of Gaussian filtering instead of box filtering. In each of the following subproblems, provide a result (either in the spatial domain or frequencydomainasindicated)andexplainwhytheresultlooksthewayitdoes. (a) (4 points.) Construct a Gaussian filter using gaussfilt with C =· 100 0 0 100 ¸and look at it in the frequencydomainwith fftshift. HowdoesitcomparetotheboxfilterinProblem2b? (b) (4 points.) Apply the above Gaussian filter to the input image. What does the result look like in the spatial domain? (c) (4points.) Whatdoestheaboveresultlooklikeinthefrequencydomain? (d) (4 points.) Construct a Gaussian filter using gaussfilt with C =· 900 0 0 900 ¸and apply it to the input image. Howdoestheresultdifferfrompart(b)? (e) (4 points.) Construct a Gaussian filter 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 filter using gaussfilt withC =R>DR. Whatdoesthisfilterlooklikeinthefrequencydomain? (g) (5points.) Whatistheresultofapplyingthisfiltertotheinputimage? Carefullyexplaintheresults.
4. (20points.) Considerthehigh-boostspatial-domainfiltergivenby 1 16 
−1 −2 −1 −2 28 −2 −1 −2 −1
 . (a) (5points.) InMatlab,displaythemagnitudeofthe2D256×256DFTofthisfilter,centeringsotheDCterm isatthecenteroftheimage. Interpretwhatyousee. (b) (5points.) Applythefiltertotheimage tiger.png andverifythatthisisindeedanedge-enhancingfilter. (c) (10 points.) With paper and pencil, explicitly compute the frequency response H(u,v) of the high-boost filter. Youshouldgetaclosed-formanswerinvolvingtrigfunctions.