For this project, an image filtering function was written and then used to produce "hybrid images" of pairs of images. Hybrid images are defined here in a paper by Oliva, Torralba, and Schyns. Essentially, two images are taken into consideration. One is filtered such that all that remains are the low frequency componenets of the image; the other, only high frequency components remain. When blended, this images appear differently at varying viewing distances.
I will now explain in detail the image filtering function, and present the result of using this function to create hybrid images.
The algorithm used for the function closely follows the classical definition of filtering: given a image f and a filter g, the output image h is defined as:
h[m, n] = Σk, l g[k, l] f[m+k, n+l]
Each element of h is the inner product of the filter and the region upon which the filter is situated. With this consideration, the function can be made a bit simpler to reason about, and can utilize some of MATLAB's functions (which are faster to run than using for-loops, due to their implementation in FORTRAN).
// Calculate the appropriate amount to pad
extra_rows = floor(num_rows(filter) / 2);
extra_cols = floor(num_cols(filter) / 2);
// Pad the image symmetrically by the extra rows and columns
padded = pad_image_symmetrically(image, extra_rows, extra_cols;
for m from 1 ... num_rows(image)
for n from 1 ... num_cols(image)
// Get the region of the padded image to filter
region = padded[m ... num_rows(filter) + m, n ... num_cols(filter) + n]
// The value of the output at [m, n] is the inner product of the
// filter and the region
output[m, n] = filter · region
The above code was implemented in MATLAB, and run to produce the results seen below.
It's worth noting two things about the design of this algorithm:
Here are some of the results of the filtering algorithm on a picture, with different filters applied.
fig. 1 identity filter | fig. 2 blur filter | fig. 3 large blur filter |
fig. 4 high pass filter | fig. 5 laplacian filter | fig. 6 sobel filter |
As you can see, the filters appear to work well on the images, and no strange discolorations occur around the edges of the images since a symmetrical padding strategy was used.
With the above algorithm, five hybrid images were produced, drawn from ten total images. The pairings were images of:
From the gallery below, it is clear to see that the hybird images do indeed appear differently depending on viewing distance.
fig. 7 high frequency image | fig. 8 low frequency image | fig. 9 hybrid image |
fig. 10 hybrid image scaled sequence |
fig. 11 high frequency image | fig. 12 low frequency image | fig. 13 hybrid image |
fig. 14 hybrid image scaled sequence |
fig. 15 high frequency image | fig. 16 low frequency image | fig. 17 hybrid image |
fig. 18 hybrid image scaled sequence |
fig. 19 high frequency image | fig. 20 low frequency image | fig. 21 hybrid image |
fig. 22 hybrid image scaled sequence |
fig. 23 high frequency image | fig. 24 low frequency image | fig. 25 hybrid image |
fig. 26 hybrid image scaled sequence |