Algorithms
pyramids(im, N) calculates the Gaussian and Laplacian pyramids for a image im, with N levels. The results from each level of the Gaussian pyramid and the Laplacian pyramid are stored in arrays to be output. The Gaussian filters are implemented using the imfilter() function with fspecial('gaussian') filter. Filter size is set to about 6 times that of sigma, while sigma values for the image is decided with trial and error. Generally, larger images work better with bigger filter sizes and larger sigma values. The Gaussian filter is applied N times to the same image, and each pass constitutes one level of the Gaussian pyramid. At each level, the image loses data, and can be resized to half of its original size (using imresize). Then, in the following level, the gaussian filter size would be halved as well. This will exponentially increase the efficiency of the algorithm. However, halving the filter size can create rounding errors, that become very substantial when filter sizes are small. Hence, it is a good idea not to resize images for smaller filter sizes. Each level of the Laplacian pyramid is obtained by taking the difference between the previous Gaussian image and the newly filtered version (before downsizing).
HybridImage(gaussian1, gaussian2, laplacian1, laplacian2, cutoff1, cutoff2) produces a hybrid image from the Gaussian and Laplacian pyramids of the two component images, as well as the cutoff point, indicating the cutoff-frequency. This is done by simply taking the gaussian1 at level cutoff2, and adding each level of laplacian2 less than cutoff2 (i.e. 1-cutoff1) to that image. This creates a hybrid image with the low frequency image from the second image, and the high frequencies of the first image. If the pyramids are downsized, this procedure must first resize the images to the same size (original image size) before adding them.
Results
without further adieu, let's take a look at some hybrid images that I have created.
1. cat and dog (filter size=14, sigma = 2.5):
Original images:
Hybrid Image:
2. Derek and Nutmeg (filter size=18, sigma = 3):
Original images:
Hybrid Image:
3. Marilyn and Einstein (filter size=11, sigma = 1.7):
Original images:
Hybrid Image:
Extra Credit
Images can be combined while retaining their color as well.
There are three ways that color can be distributed:
1. The high-frequency component shows color
2. The low-frequency component shows color
3. Both components show color.
1. cat and dog in color (filter size=14, sigma = 2.5):
low-frequency component shows color:
high-frequency component shows color:
both components shows color:
Comparing the three color combinations, it appears that showing only the low-frequency colors emphasize the low-frequency component more, making the high-frequency component (i.e. the cat) more difficult to see. When only showing the color from the high-frequency component, as in the second image, the hybrid effect is the most pronounced. Even though the colors are hard to see, the hybrid effect remains intact. When showing colors from both components, the lower-frequency colors still triumph over the high-frequency colors, accentuating the low-frequency component (i.e. the dog) easier to see. However, when considering both color and the hybrid effect, showing colors for both components work out quite well.
2. Expressions - sad/happy baby in color (filter size=5, sigma = 0.9):
Original images:
Hybrid Image: