Project 1: Hybrid Images

Hobart Reynolds (hcreynol)

September 26, 2011


A hybrid image is a combination of two images so that it appears as one image when viewed at close range and as the other image when viewed at distance. In order to do this, the high frequencies of one image must be combined with the low frequencies of the other image.

Algorithm

Step 1: Two images are selected to be combined. In order to create a reasonable combination, the user attempts to align the images so that the features of the two images would overlap (such as aligning the eyes of faces). The images are rescaled so that they will be the same size.

Step 2: Gaussian and Laplacian pyramids are generated for each image. A Gaussian pyramid is generated by creating a Gaussian filter (an image filter representing the two dimensional Gaussian distribution) and iteratively blurring the current level of the pyramid (starting with the original image) with the filter, then scaling by a factor of 0.5 (down-scaling by a factor of 2 in each dimension) to create the next level of the pyramid. A Laplacian pyramid is generated by taking each pair of levels in the Gaussian pyramid, scaling the smaller image back up to the size of the larger image, then taking the difference. In this way, the Laplacian pyramid contains the frequencies that were lost in the transition between the levels of the Gaussian pyramid. (The Laplacian pyramid had one fewer level than the Gaussian.)

At this point, an image could be reconstructed using the smallest image in the Gaussian pyramid and the Laplacian pyramid. By resizing the smallest image in the Gaussian pyramid to match the smallest image in the Laplacian, then adding them together, one could reconstruct the previous level of the Gaussian pyramid (since the Laplacian held the differences between the levels.) By repeating this procedure, one could eventually reconstruct the first level of the Gaussian pyramid, which was the original image.

Step 3: Using this principle, the hybrid image is created by selecting a cutoff level. The reconstruction procedure explained above would proceed on the second image until reaching the cutoff level. At that point, the reconstruction procedure would continue, but would be adding in the images of the Laplacian pyramid of the first image, rather than the Laplacian pyramid of the second image. This creates a hybrid image that contains the higher frequencies of the first image with the lower frequencies of the second image.


Parameters

There were a number of parameters that could be set to change the algorithm: the number of levels of the pyramid, the scale factor between the levels of the pyramid, the variance of the Gaussian filter, and the cutoff level to be used when combining the images. I attempted to experiment with all of these parameters.

I decided to use 8 levels for the Gaussian pyramid (7 for the Laplacian) and a scale factor of 0.5 between the levels of the Gaussian pyramid. Because down-scaling the images reduced their size so rapidly, even when different scale factors were used, I decided that using more levels in the pyramid or a different scale factor would not really improve the hybrid images.

I decided that using a variance of 1 for the Gaussian filter was preferable. Using a higher variance would more thoroughly blur the image. I discovered that this was somewhat problematic because it meant that when combining the pyramids, the Laplacian levels of the second image would be very blurry. This meant that the second image would be much more blurry than the first in the final hybrid image, sometimes to the point of being unrecognizable.

However, choosing the cutoff level could vary from image to image, and had a great impact on the quality of the hybrid.


Results

Below are some hybrid images which I created. The table shows the first and second images (not the original images, but the images after they had been aligned and scaled to the same size), the hybrid produced, and the cutoff level used to produce them. In this case, level 1 of the pyramid corresponds to the largest image in the Laplacian pyramid (which contains the highest frequencies), level 2 to the second largest, and so on. The cutoff level indicates the first level for which the first image's Laplacian pyramid is used (so, if the cutoff is 3, then the image is the combination of the smallest Gaussian and levels 7, 6, 5, and 4 of the second image, and levels 3, 2, and 1 of the first image).

For these images, I chose cutoff levels so that the hybrid images used few levels (only two or three) from the first image. Because of this, the first image often appears to be faintly superimposed over a blurry version of the second image. While this may not seem to be the ideal hybrid, I decided on this approach because it more clearly displayed the transition between the two images when down-scaling. Because so few levels of the first image's Laplacian pyramid were used, those frequencies disappear faster when the image is down-scaled, allowing the second image to be seen. Additionally, using fewer levels of the first image meant using more levels of the second, which allowed to second image to be much more clear when the image was down-scaled. In many cases, I found that increasing the cutoff level would produce a hybrid for which, when down-scaled, the first image remained visible, and/or the second image was so blurry that it was unrecognizable. So, I found it preferable to use a lower cutoff to a higher one, even though it caused the features of the first image to be faint in the hybrid.

In the table below, the first two rows show the same cat and dog images combined in different orders. These hybrid images appear to be better than most of the others. I suspect that it is because the dog and cat have similar facial contours, and their texture (fur) is very similar, and so they combine more easily than some of the other images (such as the man and the cat).

First Image
Second Image
Hybrid Image
Cutoff
3
3
2
3
2
2
2

External Sources:
Elephant image - http://www.inkity.com/shirtdesigner/prints/clipArt1/CORB0326.JPG
Tiger image - http://www.vistawallpapers.com/image.php?v=./data/media/45/Bengal_Tiger_Profile_Portrait.jpg