Project 1: Image Filtering and Hybrid Images

Image Representation in matrix format.

Human vision is incredibly easy. We open our eyes and perceive an incredibly detailed and information rich world. Unfortunately, the same can't be said for computer vision. Tasks like depth perception, boundary detection, and object recognition, all of which come so naturally to us, are very difficult for a computer. Part of the reason is that its core, the visual word for a computer is just a matrix of pixel values. If computers are to make any progress in interprating this visual world, they must have a way of effectively interacting with this matrix.

Image Filtering

One such way is through image filtering. Image filtering is a technique that allows us to edit and gain information about an image, such as by blurring an image or detecting edges. Image filtering works through a simpe approach. Given a filter of MxN size, the filter is slided successively over the image and the dot product is taken between the filter and the area of the image currently overlapped. The formula is shown below, where f is the filter and I is the image.

Formula for filtering an image.

One of the issues with filtering is resolution lose due to the outer pixels being excluded. This can be dealt with in a few ways. One way is to simply pad the edge of the image with zeros so that the result of filtering is exactly the same size as the original. While this works fine, it can lead to a black halo around the edge of the resulting image for obvious reasons. Another approach is to pad the image by reflecting over the edges. This can lead to smoother results. In my implementation, I use the symmetric reflection approach.

As mentioned before, one application of image filtering is to blur an image by removing the high frequencies in the image. While several different filters can used for this, the Gaussian filter provides very nice results and is widely used for this purpose. The Gaussian filter works by weighting the center of the filter the most with the surrounding pixels being given weights proportional to their distance to the center. The filter is shown below along with the result of blurring.

Gaussian Filter (Left). Original Image (Middle). Blurred Image (Right).

Hybrid Images

One application of image filtering we'll be looking at in this project is changing the frequencies present in an image to play with how we perceive the image. In particular, we will implement the hybrid image technique introduced by this paper by Olive, etc. Hybrid images are the result of combining two images, one with low frequencies excluded and the other with high frequencies excluded. What makes these images striking is how they look different at different distances. Humans perceive low frequency up close and high frequency from afar, so by taking the low of one and merging it with the high of another, we can effectively see two different images in one depending on the distance from which we see it.

For instance, here we can see the difference between a low-pass filter and high-pass filter. The high-pass filter excludes all the frequencies that don't meet a certain threshold, while the low-pass excludes the frequencies that don't exceed a certain frequency. To generate a low-pass image, a simple Guassian filter is used. To generate a high-pass image, the gaussian blurred image is subtracted from the original image, leaving only the high frequencies. These are visualized blow.

Original Image (Left). Low-pass Image (Middle). High-pass Image (Right).

In my implementation, I perform the filtering in the spatial domain. I use only two for-loops, utilizing the broadcasting abilities of matlab. As mentioned before, I also use symmetric padding to ensure the resulting image have the same size as the original.

Results

Here are some results with the images kindly provided to us.

Hybrid Image Results. High-pass on the left. Low-pass on the middle. Hybrid on the right.

I also played around with some images of my own. Most looked terrible, but I thought I'd throw in a few just for kicks. The first you'll see is of the American hero, snoop lion, formely known as snoop dog. I had some trouble lining up their eyes, but it ended up looking okay. I also remembered seeing a side by side of Miley Cyrus and Justin Bieber a while back, so I thought it might be interesting to see what happens when you morph the two. Funnily enough, the result is basically the same image. The final image was my attempt to recreate the great painting "Lincoln in Dalivision" by the eternal Salvador Dali. As you can see, it doesn't look the best, but it's still interesting to compare.

Hybrid Image Results with my own images. High-pass on the left. Low-pass on the middle. Hybrid on the right.

Extra Credit

A meme to say I didn't do any extra credit for this project (though it'll be a different story for the next one).