CS 143 / Project 1 / Image Filtering and Hybrid Images

Part 1: My Filter

For my implementation of the filter, I began by assigning the passed image and filter files to variables, I and f. Then I stacked the filter values in a column vector and transposed it to a row vector, for the eventual vector multiplication I will do to get the dot product of the sections of the image with this filter vector. I then use the line:


pads = floor(size(f)/2);

to get the size of the necessary padding. The above equation halves whatever the dimensions of the filter are, and then rounds down to compensate for the anticipated odd dimensioned filter size. After this I use the "padarray" function to pad the image variable with a reflection of the edge pixels, by using the matlab built in "padval" value "symmetric". After this I use three calls of im2col, one for each layer of the 3-d array that makes up each image. im2col takes a block of the size I specify and pulls out all the neighborhoods within the given image that are that same block size. It puts each neighborhood in a large array, where each column represents one of these neighborhoods, and the number or rows is determined by the area of the block. In my code I called these B1 - B3. After this I compute the dot product of the filter vector with each of the columns in each of these arrays, and then concatenate the results into one long vector that represents all the outcome values for the final layers of the image. Once that is done, I simply reshape the image to the original dimensions given these new values, and output the image.

Here are the results of executing the test code with my filter:

Part 2: Hybrid Images

The steps for constructing each hybrid image are fairly straightforward. First I use my filter to apply the gaussian filter to the first image. This returns a low frequency image. Then I apply the gaussian to image2, and subtract the result from image2. This returns a high frequency image. Constructing the hybrid is then simply a matter of adding these two together. For the cat/dog hybrid I used a cutoff frequency of 7, for the other two here I used a cutoff frequency of 5.

Here are some hybrid components and results:

Scale variation to show effect: