HW1 : MATLAB warmup

Due: 10/13 11:59pm EEE Dropbox

Using MATLAB [60 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).

  1. Read instructions for submitting homeworks.

  2. Read info on MATLAB @ UCI

  3. I recommend working through this concise MATLAB tutorial. Open an interactive session in MATLAB and test the commands in the tutorial by typing them at the prompt. (You can skip this step if you are already familiar with MATLAB.)

  4. 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. Do not submit a screenshot of the result of typing these command.

    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]);

  5. Use "imread" to load in a grayscale image of your choice and take a 100x100 sub-region of it. Given the 100 x 100 uint8 matrix representing that image, write a few lines of code to do each of the following. Try to avoid using loops.

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

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

    3. 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.

    4. Display the bottom right quadrant of A.

    5. 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.

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

    7. 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]'.

    8. Use the min and find functions to set x to the minimum value that occurs in A. Find the first occurrence of this minimum value in A and set r to the row it occurs in and c to the column it occurs in.

    9. 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.

    Programming: computed average images [40 points]

  6. Write a program that will average a collection of images, compute the standard deviations at each pixel, and display the results.

    The images below give some examples that were generated by averaging "100 unique commemorative photographs culled from the internet" by Jason Salavon. Your program will do something similar.

    Download the images provided on the course website for this assignment here . There are two sets, set1 and set2. Notice that they are all the same size within a single set. Then write code to do these things per set of images:

    1. Compute the average image in grayscale.

    2. Compute the average image in color, by averaging per RGB channel.

    3. Compute a matrix holding the grayscale images' standard deviation at each pixel (i.e., X(i,j) holds the standard deviation across all the images' gray pixel intensities at row i, column j).

    4. Display each of the above

Apply these steps to the two sets, separately. In your write-up, briefly explain the results -- why do they look the way they do?

Hints

  • Be sure to do the necessary typecasting (uint8 and double) when working with or displaying the images. Some useful functions: title, subplot, imagesc, imshow, std, mean, imread, rgb2gray, dir.

  • It will often be the case that you want to display some data in the form of an image (e.g. the standard deviation in the problem above). I recommend using "imagesc" for such purposes since it scales the colormap to cover the range of the data nicely.

  • The following code fragment can be used to loop through all the image files in one directory (here assuming your images are in a sub-directory named images, with .jpg extension):
          filelist = dir('images/*.jpg');
          for i=1:length(filelist)
                   imname = ['images/' filelist(i).name];
                   nextim = imread(imname);
          . . .
          end
        

  • Read in instructions for submitting homeworks.

Acknowledgements

Original version of this assignment was prepared by Kristen Grauman.