EN161 - Image Processing and Understanding
Lab 4: Filtering/Template Matching
Due Tuesday 10/1 
NOTE: Problems should be done in MATLAB.  Type up your solutions for each one including: (1) The answer to any questions posed, (2) any resulting images (include in document), and (3) the name of any functions you used. 

Zip or tar your document with your source code (m-files) into a file called [Lastname_FirstInitial_Lab4.zip/tar] and email it to mcchang@lems.brown.edu with the subject "EN161 Lab4".

Overview:
This lab introduces some image warping methods, and introduces various filtering methods by comparing the strengths and weaknesses of mean, median and Gaussian filters.
Data:
Right click on link and use "Save Link As" to save the images.
Image A
Image B
Image C
Image D
Image E
Image F
Image G
Image H
Problem 1:
Down sample Image A to 1/2 of its original size using a "nearest-neighbor" function, save it as half-A.jpg. Now down sample Image A to 1/4 of its original size save it as quarter-A.jpg.  Repeat the process on Image B using an averaging function.
Problem 2:
In this problem you will test out various interpolation techniques on the images you created in Problem 1.  You will do this by reconstructing the original images (A and B) from your down sampled images and judge the success of each method.

2.1 Using Linear Interpolation:
a.  Enlarge half-A.jpg and half-B.jpg to its original size.  Create the difference image* from your reconstructed versions and the originals.  Comment on the reconstruction success.

b.  Enlarge quarter-A.jpg and quarter-B.jpg to its original size, create the difference images of these reconstructed images and the originals.  Comment on the success of these applications.

c.  Take the difference image of the resulting reconstructed images from part 1 and part 2.  Discuss the resulting difference images.

2.2 Repeat with Sinc Bilinear Interpolation

*note:  a difference image is a greyscale image, the same size as the two images in consideration, whose pixels represent the difference between the images.  It is merely the result of subtracting one image from the other.  The higher intensity pixels represent a higher difference, and a lower intensity pixel represents a smaller difference.

Problem 3:
For this problem you can take advantage of the MATLAB functions filter2 and conv2 (use help to see the usage of each).  Also for median filtering you can use medfilt2.

(Notice that Image C contains more diffused and more continuous distribution type white noise and Image D is contaminated by isolated speckle noise)

(A)  Perform an average (mean) filtering on Image C (to do this, you need to define a 3x3 kernel then use either filter2 or conv2)

(B.1) Perform a Gaussian Filtering on Image C, take the separability property of Gaussian filters into account and use Sigma=1 and try 3x3 and 5x5 kernel widths.  Is there any relationship between kernel width and the results of your filtering? 

(B.2) Now try Sigma = 2 and kernel width = 7,  what are the differences with part B.1?

(C) Use a 3x3 window to perform a median filtering on Image C.

(D) Perform an average filtering on Image D

(E) Perform a Gaussian smoothing on Image D by taking the separability property of Gaussian filter into account.   Use sigma=1, kernel width 5. 

(F) Perform a median filtering on the Image D using a 3x3 window. 

(G) Using your observations from solving (A)-(F), compare and contrast the relative performances, advantages and disadvantages of the three algorithms. 
In particular, which one is the best for each image, and what are the problems you observed with the others? Among considerations of importance are: noise suppression; edge smoothing; resolution deterioration, e.g., two nearby edges get smoothed into one another. What are the other considerations of important? Illustrate these considerations by refering to certain image regions.
 

Problem 4:

Construct a template as specified below and create a template matching program.  Your program should use the template on the input image and find any instances (run it on Image E as test data).  If you find any instances of the template pattern in the image, display the test image with only the found template patterns remaining (remove any "non-template" elements).  This operation is similar to a filtering operation where you have a template (filter) which you need to run over the entire image and track the output.  If the output of the template at any given point is high enough (you have to determine how high is enough) then you have a match.  With binary images (like in this assignment), you will have either a yes or no result of the matching at each pixel.

Template to use:



 
Super Challenge:
See if you can use template matching to isolate all the instances of the letter 'a' in images G or H