CS 143 / Project 1 / Image Filtering and Hybrid Images

The hybrid image produced by my project. Look at that adorable catdog.

My filter function first pads the inputted image to simplify the later logic that handles actually applying the filter at a given pixel. If I didn't pad, there'd be a lot of index trickery, and I'd have to not express the filter application in terms of matrices.

Once I get to the individual channels, I extract a matrix of the same size of the filter from the image. This is then element-wise multipied with the filter and then all elements are summed together. I decided to express it in terms of matrix operations because that's all matlab can do efficiently. ;)

For the actual creation of the hybrid image, I followed the comments exactly. I applied the filter to both images. Then for the second image, I subtracted the filtered version from the original to remove the lower frequencies. Then, I added the two resulting images to create the hybrid image with low frequencies from image1 and high frequencies from image2.

Matlab filtering

The heart of filtering happens through an element-wise matrix multiplication and then summing over the resulting matrix's elements. That code is duplicated below. It happens for every pixel and every channel at that pixel.


submat = padded_image(r:r+filter_dim(1)-1, c:c+filter_dim(2)-1, channel);
filtered_image(r, c, channel) = sum(sum(filter .* submat));

Results in a table

Using my project, I made a few of my friends into fruit.

i hate matlab