CS 143 / Project 1 / Image Filtering and Hybrid Images

Example of a Hybrid Image.

Image filtering forms the basis of computer vision allowing a remarkable amount of image manipulation. Filters can, among many other abilities, blur and sharpen, highlight vertical or horizontal lines, and remove frequencies within ranges. The goal for this project was to write a version of Matlab's imfilter procedure called my_imfilter. This procedure takes an image and a filter and applies the filter to all pixels of each color channel. It does this through four steps:

  1. Padding the image with a symmetric reflection of the image edge
  2. Iterating through every placement of the filter across the image with the filter center on an image pixel
  3. Dot producting where the filter overlies the image to produce a scalar value which becomes the value at the center pixel
  4. Once the iteration is finished, removing the padding from the image.

Results of some common filters

Box Blur

Gaussian Blur

Sobel

Laplacian

Hybrid Images

One interesting application of imfilters is creating hybrid images. This process merges two images into one in such a way that different distances from the image reveal each component image separately. This effect is achieved by filtering the high frequencies from one image and the low frequencies from the other and then adding the results. At longer and shorter distances, different frequencies stand out. Generating the low frequencies is a simply matter of applying a Gaussian blur to the image. The high frequency component is generated by first applying the Gaussian blur and then subtracting that image from the original image. By changing the standard deviation of the Gaussian blur a different cutoff frequency between high and low frequencies can be obtained.

Here is the original image cat image.

Here is the original image dog image.

Here is the result of a Gaussian blur filter with dimensions 25 x 25 and standard deviation 7 applied to the dog.

Here is the result of first the same Gaussian blur applied and then that image being subtracted from the original cat image.

Selected Hybrid Images