Computational Photography and Image Manipulation

Programming Assignment 1

This assignment is intended to familiarize you with image filtering and frequency representations.

Save your images that you’ll use for the results and your report in png format.

~~~ Find the helper data and code for Part 2 here. ~~~

Due date: Tuesday, October 8, by midnight

Part 1: Gaussian and Laplacian filters (60 pts)

Find two natural photographs of your own, or over the internet. One of the photographs should have a lot of high-frequency content (sharp edges, complicated textures etc.) while the other should be balanced in content. Report the results using both of the images and comment on any significant differences between the results.

Part 1.1: Image filtering (10 pts)

Implement two functions, LPF(image, sigma, kernelsize) and HPF(image, sigma, kernelsize), that return a low-pass or a high-pass filtered version the input image respectively using Gaussian kernels of the specified size and standard deviation.

Hint: The high pass content of an image can be extracted by subtracting the low pass filtered image from the original image. Hence, to get a high pass filter kernel from a low pass one, you can subtract the LPF kernel from a unit impulse filter.

Hint: Useful MATLAB functions: imfilter, fspecial

Using your LPF and HPF functions, filter the input image using different standard deviations (0.5, 1, 3.5) and kernel sizes (5x5, 15x15), apply them to the test image and observe the results. Comment on the effects of filter size for LPF results and effects of the standard deviation for HPF results.

Source files to be submitted: LPF.m and HPF.m functions for the two filters, Part11.m script that reads your images, applies the filters and shows the requested results.

Part 1.2: Image subsampling and aliasing (20 pts)

When downsampling an image, it is often necessary to apply a low-pass filter to the image prior to resampling. This is to ensure that spurious high-frequency information does not appear in the downsampled image, i.e. to prevent aliasing.

In this part, we will implement a function subsampleImage(image, subs, sigma) to resize the input images to 1/2, 1/4, 1/8, and 1/16 by selecting every other, every 4th, 8th, or 16th of the pixels of the input image. The subs input will select the subsampling rate (2/4/8/16) and sigma will determine the amount of smoothing before subsampling. If sigma is equal to or smaller than zero, your function shouldn’t do any filtering. You should use your function LPF from the previous part.

Hint: In MATLAB, you can use subsample indices using the colon notation, e.g. (1:3:end).

First, do the subsampling without any filtering. Observe at which size aliasing starts occuring for your images. We will analyze how to prevent aliasing using low-pass filtering. By experimentation with the standard deviation of your Gaussian filter, find the minimum standard deviation to (i) prevent aliasing for your high-frequency image for 1/16th subsampling and (ii) prevent aliasing for your low-pass image for 1/16th subsampling. Report them in your write-up.

Put the resizing results in your report for both images for the unfiltered case and for two filters you determined above (hence, 3 cases for both images). Below each image, show the magnitude of the frequency content. Comment on the frequency content, aliasing, and effects of the filter size.

Hint: Useful MATLAB functions: fft2, fftshift, subplot

Source files to be submitted: subsampleImage.m function for the resizing, Part12.m script that reads your images, resizes images using different low-pass filters, and shows the requested results.

Part 1.3: LoG and image enhancement (30 pts)

Implement a function LoGfilt(image, sigma) for Laplacian of Gaussian filtering. In the function, use the kernel [0 -1 0] [-1 4 -1] [0 -1 0] for the Laplacian filter. Generate a Gaussian kernel with the specified sigma. Select the filter size of the Gaussian kernel automatically, making sure that the kernel fits inside the filter size. Convolve the Gaussian kernel with your Laplacian kernel, and then apply the LoG filter to the input image. If sigma is equal to or smaller than zero, your function should only apply the Laplacian kernel.

Hint: Useful MATLAB functions: conv2

Implement an image enhancement function enhanceImageLoG(image, sigma) using your Laplacian of Gaussian representation, that takes sigma as input. Comment on how your function works in the report. Enhance your two input images using Laplacian-only and LoG using an appropriate sigma. Comment on the results, especially around meaningful edges and noisy regions.

In your report, show both the LoGfilt() result and enhancement results side by side for both cases and both images.

Hint: Useful MATLAB functions: imagesc, colormap

Source files to be submitted: LoGfilt.m and enhanceImageLoG.m functions, Part13.m script that reads your images, filters and enhances images and shows the requested results.

Part 2: Hybrid Images (40 pts)

Hybrid images are static images that change in interpretation as a function of the viewing distance. The basic idea is that high frequency tends to dominate perception when it is available, but, at a distance, only the low frequency (smooth) part of the signal can be seen. By blending the high frequency portion of one image with the low-frequency portion of another, you get a hybrid image that leads to different interpretations at different distances.

Here, we have included two sample images and some starter code that can be used to load two images and align them. The alignment is important because it affects the perceptual grouping.

First, you’ll need to get a few pairs of images that you want to make into hybrid images. You can use the sample images for debugging, but you should use your own images in your results. Then, you will need to write code to low-pass filter one image, high-pass filter the second image, and add (or average) the two images. Use your filters from Part 1.1 for all filtering operations. The cutoff-frequency of each filter should be chosen with some experimentation.

We provide you with a backbone code with an interactive image alignment function.

About cut-off frequency:

The Gaussian filter impulse response is expressed by the relation in space domain:
h(x)= (1/sqroot 2 sigma) exp - (x^2/2 sigma^2),
and its frequency response is H(f) is expressed by H(f)= exp^- (f^2/2 sigmaf^2) and sigma* sigmaf = 1/2 pi,
The cut off frequency is considered = sigmaf, then one can determine sigma from the last equation.

Show two hybrid image results using two separate image pairs. For each hybrid result, please include the original images, the filtered input images, and the final hybrid image in two sizes: (i) the original size which reveals one image, (ii) a smaller version of the image that reveals the other. You should use your own image resizing function from Part 1.2.

Source files to be submitted: hybridImage.m function and Part20.m script that reads your aligned images and generate the hybrid results.

Deliverables

Your implementation, your report, and input / output image files through CourSys.

Your report should be in PDF format, and should consist of the requested results as well as your discussions on the questions asked above, the extra steps or considerations you needed when implementing the functions, and your parameter choices for the results. When showing your results in your report, make sure to include the original images next to the results.

The source files should include all the requested files above, in addition to the helper functions you might have implemented as a part of this assignment.