Project 1: Image Filtering and Hybrid Images

In this project, I implemented a generic image filtering algorithm, and then used that algorithm to create some interesting hybrid images. The algorithm is able to handle any valid image, represented as an array of singles or doubles, and any valid filter with odd dimensions. To implement the algorithm, I first zero-padded the image in length and width so that the filter could be applied in a well-defined way to each pixel in the source image. After padding, the algorithm consists of simply looping through the padded image and applying the filter to each possible region of the padded image in order, using MATLAB's dot() and sum() functions. At each position the values for the three color channels were computed independently.

To create the hybrid images, two source images were filtered and combined. One was filtered with a simple Gaussian to remove high frequencies, and the other was filtered to remove low frequencies, which was done by substracting a blurred version of the image from the original image. The filters used the same parameter for the Gaussian filter, meaning the cutoff frequencies for how much high or low frequency to remove was the same in both cases. However, for each example below, the Gaussian parameter was tuned for the best results.

As discussed in lecture, there are many other ways to pad the source image and deal with the issue of applying the filter on edges and corners. One of the drawbacks of the zero-padding approach is that it adds a black border to the image that may still be present in the filtered image or otherwise interfere with the filtering. A similar approach is to treat the image like a torus, and use pixels from the other end of the image to pad. However this leads to a similar issue, except that this padding at least pads with signal from the original image. A final approach is to pad the image with the same pixel that was on the very edge of the original image. An advantage of the zero-padding approach is that it is fast and easy to implement, while not affecting the results in many cases.

Results

The low frequencies taken from an image of a plane.

I applied my algorithm to several pairs of images, a few of which I have highlighted below. In each example the black border is visible, but does not appear to be a detriment to how strong the resulting effect is. In the table, I included three examples of hybrid images created using my filtering algorithm. Each row holds a set of images, decreasing in size. The images are all created from resizing the same original hybrid image. This is meant to simulate the effect of moving away from the screen, or having the image move away from the viewer, but it should be noted that this simulation is not perfect as the resolution of each image is different.

The high frequencies taken from a colored image of a bird. The image is actually zero-centered because the blurred image has been subtracted from the original image.






The dog/cat and Albert Einstein/Marilyn Monroe images both used a cutoff frequency of 7, and I chose a cutoff frequency of 5 for the bird/plane image, which gave the best aesthetic transition from bird to plane as the images get smaller.

Results in a table

Hybrid image of a cat turning into a dog as the image retreats.

Hybrid image of Albert Einstein turning into Marilyn Monroe as the image retreats.

Hybrid image of of a bird turning into a plane as the image retreats. This image was made from combining the previous two high and low frequency images.