Due: 4/8 12:30pm 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.
- 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.
- 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.
- 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.)
- 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]
- >> x = randperm(5);
- >> a = [1:10];
>> b = a([1:3:end]);
- >> f = [1501:2000];
>> g = find(f > 1850);
>> h = f(g);
- >> x = 22.*ones(1,10);
>> y = sum(x);
- >> a = [1:1000];
>> b = a([end:-1:1]);
- 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]
- Resize A to be 100x100.
- Sort all the intensities in A, put the result in a single 10,000-dimensional vector x,
and plot the values in x.
- Display a figure showing a histogram of A's intensities with 32 bins.
- 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
- Display the bottom right quadrant of A.
- 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.
- Use rand to write a function that returns the roll of a six-sided die.
- 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]'.
- 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.
- 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.
- Download the video frames bg.zip from the page of example videos.
- 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).
- 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]
- 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]
- 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]
- 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]
- 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]
- (Extra-credit) Extract frames from an additional video clip (say, from a webcam) and show the above results. [5 pts]
This assignment was originally prepared by Kristen Grauman.