Figure 1. A hybrid image using the low frequencies of a dog and the high frequencies of a cat.
The goal of this project is to create hybrid images such as the image in Figure 1, combing low frequencies and high frequencies from two different source images. This task is broken into four steps:
To facilitate the creation of the frequency filters, the project calls for the creation of a function, my_imfilter(), which applies a linear, 2D filter to an input image. This function replicates the default behavior of the imfilter() function. The image is padded along its border with zeros (to allow the filter to work all the way to the edges of the image), and the filter is applied to each pixel in each channel of the image.
filter_half_width = fix(size(filter,1)/2);
filter_half_height = fix(size(filter,2)/2);
for ch=1:1:size(image,3)
for r=padding_width+1:1:size(padded,1)-padding_width
for c=padding_height+1:1:size(padded,2)-padding_height
window=padded(r-filter_half_width:r+filter_half_width,c-filter_half_height:c+filter_half_height,ch);
output(r,c,ch) = sum(sum(times(window,filter)));
end
end
end
It is likely that there is an implementation that would execute faster in the Matlab environment. Given my lack of familiarity with Matlab and the simplicity of this kind of image processing, I decided a loop-based implementation is adequate.
A low-pass filter removes signals in the image with a frequency higher than some threshold. In image processing, this can be approximating through a blur operation. For this project, I use an 11x1 Gaussian blur filter with sigma = 10. This filter and its transpose are applied in sequence to achieve the behavior of a full 11x11 Gaussian blur filter.
blur_filter = fspecial('Gaussian', [11 1], 10);
A high-pass filter removes signals in the image with a frequency lower than some threshold. For the purposes of this project, I chose to approximate this behavior by simply subtracting the output of the low-pass filter from the original image. As the low-pass filtered image contains the low frequency signals, subtracting it from the original image should leave only the high-frequency signals from the original image.
With the low- and high-pass filters implemented, generating the final hybrid image is as simple as adding the low-pass output of the first image to the high-pass output of the second image.
Table 1. Low-Pass Filter Applied to Example Images
Input | ||||
Output |
Table 2. High-Pass Filter Applied to Example Images
Input | ||||
Output |
Figure 2. A hybrid image using the low frequencies of a dog and the high frequencies of a cat. Shown at multiple scales.
Figure 3. A hybrid image using the low frequencies of a plane and the high frequencies of a bird. Shown at multiple scales.