HW1

Due: 4/11 11:00am EEE Dropbox

Using Matlab [70 points]

The goal of this problem set is to become familiar with basic Matlab commands, practice manipulating vectors and matrices, and try out basic image display and plotting functions. If you are unsure what a Matlab function does, check the reference manual (at the command line, type "help" and then the command name).

What to hand in.

  1. Include a script for questions 3 and 4 (titled hw1_q3.m and hw1_q4.m) that the grader can run to generate all the given figures. Most of the following can be done in a matlab script, but feel free to call other scripts, functions (but include them in the homework zip file). When instructed to write a function, your script must call that function.

  2. Make sure each question is answered in your project writeup, including either a figure, plot, and/or an example snippet of the interactive commands and output used to compute the question.

  1. Read over the provided the Matlab tutorial. [0 pts]

    Open an interactive session in Matlab and test the commands by typing them at the prompt. (Skip this step if you are already familiar with Matlab.)

  2. Describe (in words where appropriate) the result of each of the following Matlab commands. Use the help command as needed, but try to determine the output without entering the commands into Matlab. For this part of the assignment, do not submit a screenshot of the result of typing these command. [10 pts]

    1. >> x = randperm(5);

    2. >> a = [1:10];
      >> b = a([1:3:end]);

    3. >> f = [1501:2000];
      >> g = find(f > 1850);
      >> h = f(g);

    4. >> x = 22.*ones(1,10);
      >> y = sum(x);

    5. >> a = [1:1000];
      >> b = a([end:-1:1]);

  3. Given a uint8 matrix A representing a grayscale image (hint - use "imread"), write a few lines of code to do each of the following. Try to avoid using loops. Select any image you want, or use one extracted from one of the videos on the project data page. You are free to use matlab scripts and/or functions (unless you are specifically asked to write a function). [15 pts]

    1. Resize A to be 100x100.

    2. Sort all the intensities in A, put the result in a single 10,000-dimensional vector x, and plot the values in x.

    3. Display a figure showing a histogram of A's intensities with 32 bins.

    4. Create and display a new binary image the same size as A, which is white wherever the intensity in A is greater than a threshold t, and black everywhere else.

    5. Display the bottom right quadrant of A.

    6. Generate a new image (matrix), which is the same as A, but with A's mean intensity value subtracted from each pixel. Set any negative values to 0.

    7. Use rand to write a function that returns the roll of a six-sided die.

    8. Let y be the vector: y = [1:6]. Use the reshape command to form a new matrix z whose first column is [1, 2, 3]', and whose second column is [4, 5, 6]'.

    9. Use the min and find functions to set x to the single minimum value that occurs in A, and set r to the row it occurs in and c to the column it occurs in.

    10. Let v be the vector: v = [1 8 8 2 1 3 9 8]. Use the unique function to compute the total number of unique values that occur in v.

  4. Download the video frames bg.zip from the page of example videos.

    1. Write a function that will compute the average image of all images in the current directory. Show this color image, and show a grayscale version of it (computed by averaging the R, G, and B channels together).

    2. Pick 3 random frames with people in them. Show these three images. Below, you experiment with different background subtraction algorithms, and show results for these three images. [5 pts]

    3. Average background image: Let av(x,y) be the [R G B]' vector of the average image at position (x,y). Let I(x,y) by the RGB value of one of the above frames at the same position. Define b(x,y) = ||av(x,y) - I(x,y)||^2 > t. Experiment with different thresholds t. Show results for two different t, providing explanations for where the algorithm fails and succeeds. [10 pts]

    4. Frame differencing: Implement the frame differencing algorithm, where one thresholds the difference between two pixels from neighboring frames T frames apart. Using the best threshold t found above, experiment with different frame distances T. Show results for two different T, providing explanations for where the algorithm fails and succeeds. [10 pts]

    5. 3-frame differencing: Implement the 3-frame differencing algorithm, where one computes the intersection of two binary masks obtained by frame-differencing. Experiment with different values of T. Show results for two T, providing an explanation for where it fails and succeeds. [10 pts]

    6. Adapative background modeling: Implement adaptive background subtraction, where one adaptively updates a background image by taking a weighted average of the background image used in the previous frame and the current image. Experiment with different weighted averages. Show results for two averaging ratios, providing an explanation for where the approach fails and succeeds. [10 pts]

    7. (Extra-credit) Implement Motion History images (MHI) of Davis and Bobick. Visualize results from an additional video clip (say, from a webcam) and show the above results. [5 pts]

    Hints

    Acknowledgements

    This assignment was originally prepared by Kristen Grauman.