CS 143 / Project 1 / Image Filtering and Hybrid Images

The purpose of this project was to write a function that applies a given filter to a given image. The next step was to create "hybrid images" by using our function to extract the high frequencies from one image and the low frequencies from another.

Filtering algorithm

A filter (with odd dimensions) and an image are provided. Starting with the filter aligned with the top-left corner of the image, new RGB values are computed for the pixel aligned with the center of the filter. This is done through element-wise multiplication of the filter and the pixels in the image it is aligned with. The filter then slides to the next pixel, and the process is repeated-- this happens for every pixel in the image for which a value can be calculated (those for which the filter is aligned such that it is completely over the image). The resulting image is then padded by symmetrically reflecting the pixels at each edge, to ensure that it is the same size as the original.

Below are a series of sample images that result from applying different filters to the cat image.

Extracting high and low frequencies from an image

The low frequencies from one image were extracted by using a Gaussian filter on the image.

The high frequencies from the other image were extracted by first extracting the low frequencies with a Gaussian filter, and then subtracting this low-frequency image from the original image.

The table below shows the original cat and dog images, along with the filtered version of each: the high frequencies were extracted from the cat image, and the low frequencies were extracted from the dog image.

Combining high and low frequencies to form hybrid images

The high frequencies of one image were added to the low frequencies of the other to create a "hybrid image" of the two. The table below shows a few pairs of photos, the low/high frequency versions of the photos, and the hybrid images that result from combining them.