# CSCI 507 / EENG 507 - HW2

## 1 Quick Reference

• Due date: Monday, September 25th by the beginning of class.
• Submission: Submission must be made on Canvas
• Format: Your submission will consist of 3 files: (1,2) two matlab files, and (3) a PDF file containing all text answers and image answers.

## 2 Questions

1. (25 pts) If a two-dimensional filter $$w(x,y)$$ is separable, that means that it can be written as the product of two one-dimensional filters; i.e., $$w(x,y)=w_x(x)w_y(y)$$. For example, the 2D Gaussian filter is separable, because $$G(x,y)=\frac{1}{2\pi\sigma^2}e^{\frac{-x^2+y^2}{2\sigma^2}}$$ can be written as $$G(x,y)=G_x(X)G_y(Y) = (\frac{1}{2\pi\sigma}e^{\frac{-x^2}{2\sigma^2}})(\frac{1}{2\pi\sigma}e^{\frac{-y^2}{2\sigma^2}})$$.

A 2D correlation of an image with a separable filter $$w(x,y)$$ can be can be computed by (1) computing a 1D correlation with $$w_y(y)$$ along the individual columns of the input image, followed by (2) computing a 1D correlation with $$w_x(x)$$ along the rows of the result from (1). In this way, the operation is much faster. Demonstrate this in Matlab using a 2D Gaussian filter on the “cameraman.tif” image1, and show that the results from the two approaches are identical.

Note that you can create Gaussian filters of any height and width using Matlab’s “fspecial” function. For example, to create $$Gx(x)$$, use Gx = fspecial(‘gaussian’, [1, width], sigma); I recommend setting the width to 6*sigma, so that the values of the Gaussian fall off close to zero at the edges of the filter. Use a large value of sigma, such as 20.

Turn in (answersheet.pdf):

1. An image of the result of the 2D correlation $$G(x,y)\otimes I(x,y)$$.
2. An image of the result of two 1D correlations, $$G_x(x)\otimes (G_y(y)\otimes I(x,y))$$.
3. Compute the point-by-point difference of the two above images, and report the maximum value of the difference.
4. Time the two methods, using Matlab’s tic and toc functions.
2. (25 pts) Using the method of normalized cross-correlation, find all instances of the letter “a” in the image “textsample.tif” found at http://inside.mines.edu/~twilliams/courses/CV-507/textsample.tif. To do this, first extract a template subimage $$w(x,y)$$ of an example of the letter “a” (you can use Matlab’s “imcrop” function). Then match this template to the image (you can use Matlab’s “normxcorr2” function). Threshold the correlation scores (you will have to experiment with the threshold) so that you get 1’s where there are “a”s and nowhere else. Now, you may get a small cluster of 1’s where there is an “a” instead of a single 1. To avoid multiple detections, you can apply Matlab’s “imregionalmax” function2 to the scores image before thresholding.

Take the locations found and draw a box (or some type of marker) overlay on the original image showing the locations of the “a”s. Your program should also count the number of detected “a”s.

Turn in:

1. (answersheet.pdf) Describe your method of solution.
2. (q2.m) Give the program listing, with comments.
3. (answersheet.pdf) Show the template image and the scores image.
4. (answersheet.pdf) The output number of “a”s, and the overlay image showing their locations.
3. (25 pts) You are given the binary image A and the structuring element B below (assume the origin of B is its center).

A:

B:

Turn in (answersheet.pdf):

1. Label (by hand) the 4-connected components, for foreground pixels (i.e., 1s).
2. Compute (by hand) the morphological opening of A with B.
3. (25 pts) The video “fiveCCC.wmv” found at http://inside.mines.edu/~twilliams/courses/CV-507/fiveCCC.wmv shows a target composed of five concentric contrasting circle (CCC) features.
• Read and display each image of the video, and print the frame number on the displayed image.
• Write a program that finds the five CCCs in each image, and marks each one with a cross hair or rectangle.
• Create an output video of your results and post it on YouTube.

For extra credit, also find the correspondence between the image features and the model features. Namely, label each feature with either “UL” (for upper left), “UM” (for upper middle), “UR” (for upper right, “LL” (for lower left), or “LR” (for lower right), as shown in the figure below3.

Turn in:

1. (q4.m) The program listing
2. (answersheet.pdf) A description of your solution.
3. (answersheet.pdf) The link to the posted video on YouTube.

## Footnotes:

1

Please be sure to convert the image to type “double” before doing correlations, to get the most accurate results.

2

Or, use connected component labeling (ie “bwlabel”), to find the clusters.

3

Hint: You can use the fact that there are three features in a straight line. Namely one feature (UM) is very close to the midpoint between two other features (UL and UR). Once you have found those three features, finding the other two is pretty straightforward. You may have to switch the order of (UL,UM,UR) depending on whether the other two features are on the left or right side of the line.