# ECSE4540: Homework#8 solution

\$29.99

Original Work ?

## Description

1. (25 points.) Write a function named myjpeg in Matlab that approximates the way the JPEG image compression algorithmworks,usingthefollowingsteps:
• Input the source image and a positive number τ that determines the amount of compression (a bigger numbermeansmorecompression). • Makesuretheimageisadoubleintherange[0,255]. • Subtract128fromtheimageintensities(sotheyrangebetween-128and+127). • Split the source image into 8×8 blocks, and take the 2D Discrete Cosine Transform of each block. Use the functions dct2 and blockproc. • Foreachblock,setanycoefﬁcientsthatarelessthan τ inmagnitudeto0. • TaketheinverseDCTofeach8x8blocktorecoveracompressedimage. • Add128totheresultingimageintensities. Clipvaluestothe[0,255]range. • Displaythecompressedimageonthescreen.
Turninacodelistingwithyourhomework. (Notethatyouralgorithmisdoingthresholdcoding,whileJPEGusesa kindofzonalcodingbasedonanormalizationmatrix.) Test your routine on the image guardian.png provided in the zip ﬁle using τ=10, τ=25, and τ=75. Include a printout of each image with your homework. Explain what you see in each case (it will help to put the original image side-by-side with the compressed one; look carefully at ﬁne-detail regions ofthe image). Experiment to see how large you canmake τ before you seeperceptible differences inthe image. How doesthe saved ﬁlesizechange with τ?
2. (25points.)
(a) Createapointspreadfunctionthatsimulatesmotionblurusingthecommand PSF = fspecial(‘motion’,21,11);. This creates a PSF that is roughly a line 21 pixels long oriented at an angle of 11 degrees. Apply the motion blur ﬁlter to the image death.png using the imfilter command. Remembertosupplyanappropriate3rdargumentsothatarrayvaluesoutsidethebordersareassumedtobe white. Youcanshouldseethattheimageisblurredtothepointthattextandﬁnedetailsarenotreadable. (b) The image museum-blur.png was blurred with the same point spread function as above, and there was no additional noise added to it (although be aware that saving the image as an 8-bit image actually introduces a very small amount of quantization noise). Since we know the PSF exactly and there is no noise added to the image, apply the inverse ﬁlter using deconvwnr to undo the blur. Discuss the restored image in terms of sharpness,artifacts,readabilityoftext,contrast,etc. (c) You should still observe some problems that came from the inverse ﬁlter due to the quantization noise. Instead, supply deconvwnr with a very small noise-to-signal ratio of 0.00001. How does this restored image look?
Morefunonthenextpage−→
3. (25points.) (a) Considerthe image clock2.png. Compute its Radon transform using θ rangingfrom 0◦ to 179◦ and ∆θ=2◦. Display the result in grayscale with axes labels (hint: use radon with full input and output arguments, and clip the image intensities to [0, 255], don’t scale them). Interpret what you see, paying particular attention to the ρ=0line. Howarethe θ valueandbrightspotsintheRadomtransformrelatedtofeaturesoftheoriginal image? Whyistheimageblackatthetopandbottom,andwhyisthenon-zeroregionoftheRadontransform rectangular? (b) NowrecoveranapproximationtotheoriginalimageusingtheinverseRadontransform. Rememberthatyou mustsupply the theta vector to iradon. Interpretwhatyousee. Wheredoestheresultlookgoodandwhere are there visible artifacts? Repeat the experiment by taking the forward and inverse Radon transform using ∆θ=1◦. Howhastheresultimproved? Aretherestillvisibleartifacts?
4. (25 points.) Consider the grayscale image guys.png. In this problem, you’ll look at four ways of rendering it in black and white. For each method, include the black-and-white image produced by your code, and discuss its qualitativeappearanceinsomedetail. Makesuretocasttheinputimageasa double beforestarting!
(a) First,thresholdtheimageatavalueof128. (b) Next, apply uniform ditheringby adding i.i.d. uniform randomnoise in the range [-50,50], then thresholding theresultingimageatavalueof128. (c) Third,halftonetheimagebytilingtheimageinto4×4blocks,addingtheBayermask
16×
    
1 9 3 11 13 5 15 7 4 12 2 10 16 8 14 6
     toeachblock,andthresholdingtheresultingimageatavalueof256. (d) Finally,useMatlab’sbuilt-in dither commandtoapplyFloyd-Steinbergdithering.