CS 143 / Project 1 / Image Filtering and Hybrid Images

Background

Hybrid images are composite images that blend two pictures--one picture is filtered using a high pass, and the other is filtered with a low pass. When the two filtered images are layered over each other, the human eye will see one or the other, depending on the viewing distance.

Algorithm

Here's a quick walkthrough of the algorithm. This is based off of the 2006 SIGGRAPH paper.

Before and after a Gaussian blur, for a low pass filter.

Before being able to generate a high and low pass image, we first have to have a filter. Thus, I completed the function my_imfilter() that takes in the image to be edited, and the an M×N matrix that'll serve as the filter. (Note: the image filter must be an odd-number width and height, so as to have an explicit center pixel)

First I padded the array using Matlab's built in padarray() function which adds a border around the original image. This avoid edge cases, where I try to element-wise multiply the filter against a non-existent pixel of the image.

I then use the im2col() function, which breaks up the matrix into overlapping tiles, and converts each tile to a column in a new array. I then do a similar process to the filter, whereby I call im2col() and then repmat() to replicate the resulting column. This results in two matrices that I can multiply together once to generate the resulting filtered values of each pixel, rather than iterating over the image more slowly.

I finally reassemble the image using the col2im() function.

We make the high pass filter by subtracting the low pass filter from the original image

All of this code is packaged in a funciton I defined called filterChannel() which takes in a single grayscale image, and the filter. This allows me to edit both grayscale and rgb images--when my_filter() takes in an image, it'll check whether it's a color image and thus call filterChannel() on each channel before reassembling the new image, or if it's black and white it'll just call filterChannel() on the grayscale image.

Finally, to make the actual hybrid image, I did a high frequency blur and a low frequency blur on my two respective images, and overlayed the two. This was done with a Gaussian blur.

More Images, More Fun!

Here's a few of the images I've made. It includes the two filtered images, before being blended, and a series of shrinking images.

It's a bird! It's a plane! No, it's ... both?

Cutoff-frequency: 5

Fish/Sub

Cutoff-frequency: 2

Bikes on Bikes

CATDOG

Cutoff-frequency: 3