ECSE4540: Homework#7 solution


Original Work


5/5 - (1 vote)

1. (20points.) Considertheimage hotsauce.png andthesmalltemplate letter.png.
(a) Use normxcorr2 to match the template to the image and visualize the magnitude of the result as an image. Itmayhelptouse colormap(jet) toseethepeaks. Interprettheregionswherethemagnitude ofthecross-correlationislarge. (b) Plot the peaks where the cross-correlation is greater than 0.9 as yellow rectangles the same size as the templateontopoftheoriginalimage. Thereareseveralwaystodothis,butthefunctionsregionprops and rectangle maybeuseful. Areallthepeaks“correct”locationsofthetemplate? (c) Nowtryreducingthethresholdto0.8. Explainthephenomenayouseeindetail. (d) Nowtryreducingthethresholdto0.7. Explainthephenomenayouseeindetail.
2. (20points.) Inthisproblemyou’llexplorefeaturematchingusingyourownimagesandthebuilt-infunctions inMatlab’sComputerVisionSystemToolbox.
(a) First, choose a relatively cluttered environment with lots of corners and texture for an automatic feature detector to pick up on (e.g., your desk with a bunch of books and papers on it, or your living room or kitchen). Take one picture of this environment, take 2–3 steps parallel to the scene, then take another picture. Use the detectHarrisFeatures, extractFeatures, and matchFeatures, and showMatchedFeaturesfunctionstodisplayHarrisfeaturematchesbetweenthesetwoimages(following the tutorial in the matchFeatures documentation). Critically assess the results; for example, what kindsoffeaturesarepickedup? Howwell-distributedarethefeaturesacrossthescene? (b) Now, instead of using a second image that is quite similar to the first, move substantially around the scene (e.g., rotating your camera and getting closer to/further from the scene, so a square of pixels in one image will not easily match a square of pixels in the other image). Repeat your experiment from part(a). Dotheresultsgetworse? (c) Using the same images in part (b), use the detectSURFFeatures to detect and match SURF features using the same steps as in part (a). Critically assess the results; for example, what kinds of features are pickedup? Aretherealotofgoodmatches? Aretherealotofbadmatches?
3. (20points.) WriteaMatlabfunctionthattakesan8-bitimageasinput,andreturnsthefollowingfivevalues:
• Theentropyoftheinputimage • The entropy obtained by coding horizontally adjacent (non-overlapping) pairs of pixels, divided by 2 sincewehavehalfasmanydouble-size“pixels” • Theentropyobtainedbycodingverticallyadjacent(non-overlapping)pairsofpixels,dividedby2since wehavehalfasmanydouble-size“pixels” • Theentropyoftheimageobtainedbytakingthehorizontaldifferencesbetweenadjacentpixels(wrappingfromtheendofonerowtothebeginningofthenext) • Theentropyoftheimageobtainedbytakingtheverticaldifferencesbetweenadjacentpixels(wrapping fromtheendofonecolumntothebeginningofthenext)
While there’s a built-in Matlab function called entropy, you can’t use it directly, since (for example) the differenceimageswillnolongercontainpositiveintegers. Isuggestyouwriteanentropyfunctionfromscratch thatoperatesongenericinteger(e.g.,int32)input. Youcanmakenew“images”withalargerdynamicrange for the second two computations using something like 256*(left pixel) + (right pixel). The syntax im(:) may be useful here; i.e., rearranging a square matrix, column by column, into a single long column vector.
4. (20points.) Applyyourfunctionabovetothethreeinputimagesinnoise.png,stripes.png,andcells.png. Provide the five entropy values in each case, and (most importantly) interpret the results. Note that each of these images only has 4 gray levels, so without any coding, we would use 2 bits per pixel. Each entropy corresponds to the best-case number of bits per pixel we could hope to obtain usingthe corresponding image/scheme. Clearly, you need to look at the source images and think about the corresponding probability distributionsinordertointerprettheentropies.
5. (20 points.) For the cells.png example above, I computed the histograms of original values and vertical differencesasfollows:
Value 0 1 2 3 Count 67178 247264 180960 67098
Verticaldifference -2 -1 0 1 2 3 Count 54 8791 545770 7124 508 252
DeterminetheHuffmancodesandcorrespondingaveragebitsperpixelcorrespondingtoeachdistribution; howdothesecomparetotheentropiesyoucomputedinthepreviousproblem? Notethatyoucansolvethis problembeforeactuallygettingyourMatlabcodeworking.