CS 143 / Project 1 / Image Filtering and Hybrid Images

Getting Started

I did this project in what I assume was the standard way. In order to filter each image, I first divided the image into its red, green, and blue color channels, and then filtered each channel seperately.

Padding the Image

For each channel, I first padded the channel with the correct number of zeros -- which turns out to be ((the number of rows of the filter - 1) / 2) in one dimension and ((the number of columns of the filter - 1)/2 in the other direction. This is because, if we are placing the center of the filter on each pixel in the image, then the filter will overflow by at most half its width or height.

Filtering the Padded Channel

I then looped over all of the pixles in the padded channel. Because I was starting in the padding, this meant that I could simply place the upper left corner of the filter at each pixel, and have the corresponding location in the output be the equivalent of the pixel beneath the middle of the filter. I then took the appropriate submatrix, and used element wise matrix multiplication in conjunction with the sum function to apply the filter to each segment. I then put these results into the appropriate location in the (preallocated) output channel

Putting the Image Back Together

Then I used cat to put the three filtered channels back together, and returned this value.

Producing Hybrid Images

This part is pretty simple. I used the filter provided to blur both images, then used the - function to subtract the blurred image2 from itself to get the high frequencies. I then combined the two images by adding them together. The results of this can be seen below. Note: I think that some of these would work better with a higher cutoff, but it gets slow at about 9. It was also very interesting to observe the way that the images interacted with one another. For instance, in the bicycle/motorcycle hybrid, the white background of the bike image completely washed out large chunks of the motorcycle, no matter which settings I tried.

Results in a table

Original Image1

Original Image2

Cutoff

Low Frequency Image

High Frequency Image

Combined Image

7
8
2
8
5