CS 143 / Project 1 / Image Filtering and Hybrid Images

For this project, I am implementing the image filtering function and use it to create hybrid images.

Implementing image filtering

Given an image and a filter matrix, first I pad the image with zeros on all sides to deal with image boundaries; then, I compute the value for each pixel of the new image by element-wise multiplying the filter matrix with the corresponding region of the image and then add up these products. Specifically, for each pixel i and j

result(i,j) = sum(sum(filter .* padded_image((i-(fh-1)/2):(i+(fh-1)/2), (j-(fw-1)/2):(j+(fw-1)/2))))

where .* is the element-wise multiplication; fw and fh are the width and height of the filter.

Here are examples of filtering an image of a cat with different filters.

Top: (a) an original cat image, (b) cat image with identity filter, (c) blurred cat image
Bottom: (d) even more clurred cat image, (e) cat image with Sobel filter, (f) cat image with Laplacian filter

Creating hybrid images

A hybird image is an image that can be view differently depending on the distance from the image you are observing from. It is created by combining a low frequency image with another high frequency image. The high frequency image could be seen easier when looking up close, whereas the low frequency image could be seen easier from far distance.

High and low frequency images

A low frequency image can be obtained by blurring an image and a high frequency image can be obtained by subtracting the low frequency image from the original one. Below is an example of the low and the high frequency image.

an original cat image – low-frequency cat image = high frequency cat image

Creating hybrid image from a low and a high frequency images

Combining a low frequency of an image and a high frequency of another image will result in a hybrid image. Here are the examples.

An original image of a dog and a cat.

High frequency cat image and low frequency dog image

The hybrid image of a cat and a dog.

To illustrate the viewing distance of the hybrid image, below is the same hybrid image with different sizes. Note that the larger images looks more like a cat whereas small images look more like a dog.

The hybrid images of a cat and a dog with different sizes.

Other examples

Marilyn Monroe + Albert Einstein

+ =

Motorcycle + Bicycle

+ =

Submarine + Shark

+ =

Bird + Plane

+ =