CS 143 / Project 1 / Image Filtering and Hybrid Images

This image of Einstein will turn into Marilyn when viewed from far away.

Overview

Hybrid images are images that have different interpretation depending on the distance between the viewer and the distance. When high frequency information is available, humans tend to use this information much more than low frequency information in order to interpret an image. However, this high frequency information becomes less available to the viewer the further away the viewer is located. In this writeup, I explore how two different images can be combined into a single hybrid image which differs in interpretation depending on the frequency used to interpret the image.

Description

In order to obtain the low frequencies of an image, we can filter the input image using a gaussian blur operation. The corresponding high frequencies are obtained by subtracting the blurred image from the original image. After obtaining both the low and high frequency images, we create the hybrid image by adding the high frequency and low frequency images together. Finally, in order to see both interpretations, we can downsample the hybrid image.

my_imfilter()

In order to blur an image, I wrote the function, my_imfilter(), to apply a filter to a specified image. For the my_imfilter() function, I used 3 nested for loops to loop through the entire image and apply the filter to each image patch. The filtering operation is the same regardless of whether the image is color or grayscale. The only difference is that my_imfilter() will perform the same filtering operation on all 3 color channels. In order to account for image boundaries, I padded the input images with zeros before applying the image filter. This type of padding used will not affect the hybrid image too much because the hybrid images have been centered onto the middle of the image.

Obtaining the high frequency image

The code below demonstrates one way to obtain the high frequency image. We can create a filter which subtracts a gaussian blur from the unit impluse. When applying this filter to the image, this operation will subtract the blurred image from the original image leaving the high frequency image centered at zero.


unit_impluse = zeros(4 * cutoff_frequency + 1);
unit_impluse(2 * cutoff_frequency + 1, 2 * cutoff_frequency + 1) = 1;
filter = unit_impluse - fspecial('Gaussian', cutoff_frequency*4+1, cutoff_frequency);
high_frequencies = my_imfilter(image2, filter);

Results

The first row in the table below shows the high frequency filtered image. The second row in the table below shows the log frequency filtered image. Finally, the combined images are displayed by progressively downsampling the hybrid image.

Looking at these examples, we can see that these hybrid images work quite well. At the highest frequencies, we can clearly see Einstein, a bike, a cat, and a bird. As we downsize to smaller sizes, we interpret these images as Marilyn, a motercycle, a dog, and a plane. The effectiveness of the hybrid images depends on the value of the cutoff frequency, which can be tuned to different values depending on the pair of images used.