Spring 2010 - CS477/577 - An Introduction to Computer Vision

Assignment Five

Due: Sunday night, March 28, 2010 (before 9am, Monday MORNING)

Credit (U-grad): Approximately 7 points (Relative, and very rough absolute weighting)
Credit (Grad): Approximately 7 points (Relative, and very rough absolute weighting)

This assignment must be done individually


Big picture

This assignment will provide hands on experience using convolution for image filtering. We will experiment with making images blurry and detecting edges at different scales.

Grad students will also learn a trick to speed up convolution when the filter is "separable".

Grad students will also do a review problem in color constancy.


You can do this assignment in either Matlab or C/C++.

It is probably a bit easier in Matlab, but doing some of the assignments in C may prove to be a useful exercise. If you think that vision research or programming may be in your future, you might want to consider doing some of the assignments in C/C++. If you are stretched for time, and like Matlab, you may want to stick to Matlab. Your choice!

Information for those working in C/C++.     (Updated for this assignment).

Those working in Matlab may want to look at the function: conv2


Assignment specification

This assignment has 7 parts, of which 5 are required for undergrads.

To simplify grading, you should hard code the file names in the version of your program that you give to the TA. You can assume that the TA will run the program in your turnin directory. Please give the TA sufficient information in the README to reproduce your results.

To keep things simple, we will focus on black and white (gray level) images (except the last question which is required for grads only). This means that an image is basically a matrix. Thus both in Matlab and in C it likely easiest to get the image into a matrix, work on the matrix, and then convert the matrix back to an image for IO.

The input image for this assignment is /cs/www/classes/cs477/spring08/ua_cs_only/assignments/climber.tiff .


  1. Write a program to show the magnitude of the gradient of the input image using convolution to implement finite differences. You will want to scale the brightness of your result so that it looks reasonable. Output an image based on the magnitude of the gradient as 1.jpeg.

    You can use provided routine(s) for convolution in C or Matlab. Or you may prefer to implement convolution yourself. (A naive implementation in Matlab will run much slower than the built in function--you should understand why).

  2. Now find a threshold for the gradient magnitude to determine real edges. Make a new image which is white if the gradient magnitude exceeds that threshold, and black (zero) otherwise. Likely you will find that there does not exist a perfect threshold which identifies exactly all points on all significant edges. Don't spend too much time tweaking the threshold, but do find a reasonable value. Output this as 2.jpeg.

  3. Now use convolution to smooth the image with a Gaussian mask with sigma set at 2 pixels. Use a convolution routine which does not assume anything about the mask (i.e., you should send the convolution routine the mask, so that if you wanted to change it to something else, the code would be correct). Output this as 3.jpeg.

  4. Apply the procedure from (1) and (2) to find edges in the blurred image computed in (3). Thus, for the resulting image from (3), do edge detection as in (1) and find a threshold as in (2) and output a binary image based on that threshold (as in (2)). Output this as 4.jpeg.

  5. Now convolve the image with an appropriate single mask to implement both smoothing by a sigma set to 4 pixels composed with the finite difference operation in the X direction. Do the same for the Y direction. Combine the two results, and output the new gradient images as 5.jpeg. Verify for yourself (i.e, this is simply a check---don't hand anything in) that this gives roughly the same result as doing the convolutions separately with the appropriate masks.

  6. Required for grad students only (5% extra credit for ugrads).

    A function is said to be separable (in x and y), if f(x,y)=g(x)h(y), If this is the case, then convolution with f(x,y) can be implemented as a 1D convolution by g(x) followed by a 1D convolution by h(y). Re-implement the smoothing in (3) using this approach. Verify for yourself that this gives roughly the same result as before.

    Do you expect any speed difference? Why? Do you see any speed difference? (You may want to put the convolution in a loop, or use a bigger sigma and image to test for time differences).

    Matlab users: This is just a matter of calling conv2 with different parameters.
    KJB library users: See x_convolve_matrix and y_convolve_matrix.

  7. Required for grad students only (5% extra credit for ugrads).

    Consider the case that you have two color images of the exact same scene taken under different illuminants. Suppose that you want to find the best diagonal transformation between them in the least squares sense. Derive a formula for that transformation.


To hand in the above, use the turnin program available on lectura (turnin key is cs477_hw5). You may want to hand in a single program that displays the images for the first five parts. For the last two (grad) parts, you will have to turn in additional material. PDF is likely the best choice. Don't forget to give the TA a guide to your submission in the README.