CS 143 / Project 1 / Image Filtering and Hybrid Images

Overview

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. Hybrid images are static images that change in interpretation as a function of the viewing distance. The basic idea is that high frequency tends to dominate perception when it is available, but, at a distance, only the low frequency (smooth) part of the signal can be seen. By blending the high frequency portion of one image with the low-frequency portion of another, you get a hybrid image that leads to different interpretations at different distances.

Image filtering

All the image filtering is done inside the my_imfilter() function, which receives as parameters an image and a filter matrix and returns the filtered image. The function starts by padding zeros around the image, apply the filter on the original image and remove the padded pixels at the end. The result of the filtering process can be verified on the images below. The images show the a cat image filtered with the following filters: identity, small blur, large blur, sobel, laplacian and high pass.
Different filters applied to the same image: identity filter, small blur, large blur, sober filter, laplacian filter and high pass filter

Hybrid images construction

To construct the hybrid image, we need two images, remove the high frequency information from the first one, the low frequency information from the second one and add the resulting images together. The filter used to do this will be the Gaussian filter, defined as:


filter = fspecial('Gaussian', cutoff_frequency*4+1, cutoff_frequency);
This filter will blur the image, removing the high frequencies. To remove the low frequencies we can just get the original image and subtract its blurred version from it. So, the two resulting images will be:

low_frequencies = my_imfilter(image1, filter);

blur_image2 = my_imfilter(image2, filter);
high_frequencies = image2 - blur_image2;
Finally, the hybrid image will be the sum of these two images. The cutoff frequency is a parameter that should be tuned to each image. For example, the following image shows different sizes of an hybrid image constructed using a dog and a cat images and a cutoff frequency of 7:


Where the low and high frequency images used were:


Below, it is possible to verify the impact of the cutoff frequency. The following hybrid images were created using a cutoff frequency rangin from 5 to 10 and using the same two images for each cutoff frequency:
Different hybrid images created using a cutoff frequency ranging from 5 to 10

As it can be seen, some images change more than others with the variation of the cutoff frequency, like the bicycle/motorcycle image that changes more than the dog/cat or the fish/submarine images. Also, the marilyn/einstein image did not present good results with this cutoff range, showing that different images work better with different cutoffs.

Conclusions

An hybrid image is constructed by mixing the low frequencies of one image with the high frequencies of another one. This process can be done using a blur filter to remove the undesired frequencies and produces images that show different things at different distances. In this project a filter function was implemented and used to create different hybrid images. The cutoff frequency of the hybrid image represents which frequencies will be removed from each image, and the best value can be different for each one. By experimentation, it was seen that some images present much more variation with cutoff changes than others, and that the best cutoff for one may not produce good results for another image.