Project 1: Image Filtering and Hybrid Images

Example of a sobel filtered image.

The goal of this assignment is to write an image filtering function and use it to create hybrid images using a simplified version of the SIGGRAPH 2006 paper by Oliva, Torralba, and Schyns. Image filtering is acheived by making a 2D matrix representation of an image and that of a filter. Then, for every pixel in the image, take the sum of the products of the subsection of the image around that pixel and the filter. There are a few filters that are commonly used in computer vision, all of which are used here.

  1. blurring filters
  2. sobel filters
  3. gaussian filters
  4. high/low pass filters

Implementation

In order to be able to filter the border pixels, the image needs to be padded around the edges. I chose to do so symmetrically. Once that is taken care of, this filtering can be acheived a few ways.

  1. Four nested for loops
  2. Two nested for loops and good use of matlab matrix multiplication
  3. More matlab magic

As I am not fully versed in matlab magic, I chose option two and had two nested for loops and some matrix multiplication. Taking advantage of matlab's matrix multiplication is faster than nesting two more for loops as well as looks a bit cleaner. The following code snippet shows the matrix multiplication portion for each one of the three color channels.


rtemp = paddedImage(m:m+2*rOffset,n:n+2*cOffset,1).*filter;
filteredImg(m,n,1) = sum(rtemp(:));
gtemp = paddedImage(m:m+2*rOffset,n:n+2*cOffset,2).*filter;
filteredImg(m,n,2) = sum(gtemp(:));
btemp = paddedImage(m:m+2*rOffset,n:n+2*cOffset,3).*filter;
filteredImg(m,n,3) = sum(btemp(:));

Results of Passing a Cat Through Various Filters

Hybrid Images

Hybrid images involve removing the low frequencies from one picture, removing the high frequencies of another, and then combining the two. With a working imfilter implementation, it is now possible to create these Hybrid Images.

An important thing to note, though, is that the images have to be reasonably aligned with each other for this to look right. The following two pictures show what happens when the faces of two objects are pretty close but not fully on top of one another.