CS 143 / Project 1 / Image Filtering and Hybrid Images

Blurred image generated with my_imfilter

Overview

For project 1, I was tasked with creating a matlab script which would generate hybrid images using a a custom-built filter. The actual hybrid image generation was fairly simple. As per the 2006 SIGGRAPH paper by Oliva, Torralba and Schyns, I used a guassian filter to blur images and remove their high frequencies. Once blurred images were obtained, it was trivial to obtain images with isolated high frequencies by subtracting the blurred image from the original (since the blurred image contained all low frequency content). I specified the standard deviation in pixels of a Gaussian blur in order to control the threshold between high and low frequencies. Hybrid images were then obtained by summing high frequency images with low frequency images. The gain of each frequency channel was not altered, although doing so may have resulted in more effective hybrid images.

The more difficult portion of this assignment was implementing a filtering function in matlab. The following list outlines the steps involved in my filtering function. Note that the function I wrote, my_imfilter, is heavily commented and discusses the rationale for each of these steps.

  1. Check that the filter has odd dimensions
  2. Preallocate space for the output
  3. Pad the image with zeros
  4. Calculate variables which will be used to perform filtering
  5. Iterate through the pixels of the image, apply the filter to each, and write to the output

Decisions and Issues

I decided against using padarray() and im2col() since I was interested in familiarizing myself with manipulating matrices at a low level within matlab.

As this was one of my first times using matlab, I had some difficulties implementing this project. I worked on this project on a couple different machines, and each machine had some unique issues. Among the challenges I encountered:

  1. Machines in CIT169 didn't allow users to change MATLAB's search path
  2. My home machine (windows 8) didn't play nicely with the relative file paths which specified image locations in the MATLAB support code
  3. Most notably, my_imfilter.m seems to run extremely slowly when called from proj1. While the filter I wrote correctly executes all test cases in proj1_test_filtering.m in a couple minutes, generating even one image takes exponentially longer when called from proj1.m. This behavior seems very bizarre, since the same images are used by both scripts and proj1_test_filtering.m includes a Gaussian filter. When called from proj1.m, my_imfilter.m hangs for extended periods of time inside the following nested for loop:
    
    			%calculating value of a filtered pixel
    				value = 0;
    				for k = 1:numFilterCols
    					for z = 1:numFilterRows 
    						value = value + (filter(z,k)*image(slidingWindowOriginY+z-1, ...
    						slidingWindowOriginX+k-1,c));
    					end
    				end
    		
    Note that in the previous piece of code, I use the slidingWindowOrigin variables to refer to the location of the image coordinate which corresponds to the origin of the filter. NumFilterCols refers to the number of columns in the filter, and value is the filtered value of one channel of one pixel.

High Frequency, Low Frequency, and Hybrid Example

*Gaussian blur standard deviation set to 5 pixels