Images contain regions of different frequencies. Finer structures such as texture, edges, and details occupy higher frequencies, while features like background and general shapes are lower frequencies. When we look at an image, the distance at which we are from it determines which frequencies dominate our perception. When we are close, fine details obscure low-frequency portions, and at farther distances, the high-frequency elements are not visible, and we only see the lower frequencies.
We can use this property to our advantage to construct hybrid images: a combination of two images that appears to be one image when viewed closely and the other when seen from a distance. The algorithm uses a low-pass filter to select only the low-frequency elements of one image, and a high-pass filter to get the high-frequency elements of the other. The hybrid image is constructed by simply combining the two derived images.
The first step is to construct image pyramids of the two images. For each, we construct two pyramids, one with the Gaussian filter (low-pass), and one with the Laplacian filter (high-pass). The easiest method to compute the Gaussian is to use the standard MATLAB function fspecial
. Suppose that N is the depth of the pyramid we need. Each level of the pyramid is constructed by downsampling the previous level according to a constant scale factor, then blurring the result with a Gaussian filter. The Laplacian is calculated a little differently: the nth element of the pyramid is the nth Gaussian minus the result of applying the Gaussian filter to the nth Gaussian. This is not exactly the same as applying the actual Laplacian filter, but in practice gives similar results.
To construct the final image, we combine the Gaussian of the first image, and all of the Laplacians of the second image. However, if we included all of the images from the pyramids, we would include too much information, as the high-density image would contain low-density information, and vice-versa. Therefore, using a predetermined cutoff value m, we only include the first m Gaussians from the bottom, and the first m Laplacians from the top, and add the images.
To incorporate color, there are a couple of issues: imresize
doesn't work with colored images. The process worked best if color from both images was used, but mainly from the low-frequency image (since color seems to be a low-frequency property).