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.
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.
(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.
![]() |
![]() |
![]() |
(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.
![]() |
* |
![]() |
![]() |
![]() |
(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.
(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.
![]() |
![]() |
![]() |
(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.
![]() |
![]() |
![]() |
![]() |
(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 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%.
(*) In your my_imresize function, downsampling an image using bilinear interpolation can result in aliasing artifacts. Fix this problem by first convolving the image with a Gaussian kernel of the appropriate size.
(*) Modify your above functions (other than my_rgb2gray and my_gauss) so that they also work on RGB images. That is, they should work on both grayscale images and RGB images, returning an image of the appropriate type.
(*) Convolution can be slow for large filters. If the filter is m-by-n, then the ordinary method performs O(mn) multiplications and additions per pixel. Many common filters, such as the mean, Gaussian, and Sobel filters, have a property called separability — the filter can be decomposed into an m-by-1 filter and a 1-by-n filter such that convolving the image with these two filters in succession gives the same result as convolving with the m-by-n filter. These two convolutions together perform only O(m + n) multiplications and additions per pixel, yielding significant savings when m and n are large. Modify your my_conv2 function to test for filter separability, and if the filter is separable, decompose it into two 1D filters and convolve the image with both of them.
(**) Write a function my_meanfilt (in file my_meanfilt.m) that can be called with the following command:
B = my_meanfilt(A,k);The function should convolve grayscale image A with a k-by-k mean filter, returning the result in B. B should be the same size as A, and values outside the boundary of A should be treated as zero. To make things interesting, if A is m-by-n, the function should run in O(mn) time independent of k. That is, your function should perform only a constant number of operations per pixel, regardless of filter size.
(**) Write a function my_laplace_pyramid (in file my_laplace_pyramid.m) that can be called with the following command:
P = my_laplace_pyramid(A);The function should return the Laplacian Pyramid of grayscale image A in a Matlab cell array. Also write a function my_laplace_restore (in file my_laplace_restore.m) that can be called with the following command:
A = my_laplace_restore(P);This function should take in a Laplacian Pyramid output by my_laplace_pyramid and reconstruct the original image. You'll probably want to implement the first extra credit problem before you do this one.
To turn in your project, submit a single zip file to the dropbox at:
https://catalysttools.washington.edu/collectit/dropbox/iansimon/8903The 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.