CSE 455 Project 1a: Image Filtering

Assigned: Friday, January 8
Due: Friday, January 15 (1:30 PM)

In this project, you will practice manipulating images in Matlab. You will get to experiment with image filtering and resampling, and build up some Matlab experience that will help you with later projects. In addition, some of the code you write will be useful for Project 1b, on seam carving.


Getting Started

Make sure you have access to a machine that runs Matlab. The workstations in Sieg 327 all have Matlab installed. You could also purchase the student version, or use Octave, an open-source Matlab substitute. We will be testing your code using the Matlab installations in Sieg 327, so if you use Octave or the student version, you should make sure your code functions properly in Matlab in Sieg 327 before submitting. In particular, you should not use functions from Matlab's Image Processing Toolbox, as this is not installed in the lab.

You may find the following images useful for testing: mandrill.png, checkerboard.png, lena.png (read about Lena here). Of course you may test your code on any images you like.

After loading an image A in Matlab (using imread), you should issue the command:

B = double(A) / 255;
This will ensure that the pixel values are represented as floating-point numbers between 0.0 and 1.0. For the functions you write, you may assume that images are already in this format.


Code to Write

  1. (10%) Write a matlab function my_rgb2gray (in file my_rgb2gray.m) that can be called with the following command:

    B = my_rgb2gray(A);
    The function should convert an RGB image A (an m-by-n-by-3 matrix) to a grayscale image B (an m-by-n matrix). You can do this with one line of code. Note that conversion from RGB to grayscale is not unique, as there are many possible weightings of the three color channels. A typical one is 30% red, 60% green, and 10% blue.

  2. (20%) Write a Matlab function my_conv2 (in file my_conv2.m) that can be called with the following command:

    B = my_conv2(A,H);
    The function should convolve a grayscale image A with a filter H (not necessarily square), yielding a filtered image B. B should be the same size as A, and image values outside the boundary of A should be treated as zero. For just this part of the assignment, you may write the function using multiple nested for loops. You may not use the built-in Matlab functions conv2 or filter2 to perform the convolution, though you may use them for comparison. Remember to implement convolution and not cross-correlation.

    *
  3. (20%) Write a Matlab function my_gauss (in file my_gauss.m) that can be called with the following command:

    H = my_gauss(k,sigma);
    The function should create a k-by-k Gaussian filter with standard deviation sigma. The filter values should sum to one. Try to do this without using a for loop.

  4. (20%) Write a Matlab function my_medfilt2 (in file my_medfilt2.m) that can be called with the following command:

    B = my_medfilt2(A,k)
    The function should run median filtering on grayscale image A using a k-by-k window, returning the result in B. Again, B should be the same size as A, and you should treat values outside the boundary of A as zero.

  5. (10%) Write a Matlab function my_gradient (in file my_gradient.m) that can be called with the following command:

    [DX DY] = my_gradient(A)
    The function should compute the gradient of grayscale image A, and return the result in DX (horizontal derivative) and DY (vertical derivative). DX and DY should be the same size as A, and you should treat values outside the boundary of A as zero. This function should make use of your my_conv2 function. There are multiple acceptable filters to use. One good choice is the Sobel operator.

  6. (20%) Write a Matlab function my_imresize (in file my_imresize.m) that can be called with the following command:

    B = my_imresize(A,m,n);
    The function should resize grayscale image A to an image B with m rows and n columns, using bilinear interpolation. Again, you may write this function using for loops, though it is possible to vectorize it. You may not use the built-in Matlab function interp2 to perform the interpolation. Hint: for each pixel location in B, determine the corresponding (real-valued) location in A, and use the four adjacent pixels.


Extra Credit

Extra credit problems do not count towards your score for the project, but are accumulated separately. One star (*) is awarded for easier extra credit problems, with more stars for more difficult problems. At the end of the course, the stars you've earned will be used to adjust your final grade upward by at most 5%.


Submission

To turn in your project, submit a single zip file to the dropbox at:

https://catalysttools.washington.edu/collectit/dropbox/iansimon/8903
The zip file should be named project1a.zip and contain all of your M-files and a readme.txt file telling us which extra credit problems you implemented, and anything else you think we should know about your project. If you only implemented the basic project, you can leave out the readme.txt file. Your zip file for this project should not contain any subdirectories.