Example of a hybrid image.
This project constructs hybrid images by composing two images of the same size in which the orientation of the underlying objects are spatially aligned. This is achieved by the following process:
The filtering process is implemented using convolution in the spatial domain where a Gaussian kernel is used. A parameter is used to control the amount of filtering.
The convolution is programmed in the spatial domain instead of the frequency domain because we do not expect a filtering kernel of large size. Also, it is simpler and reinforces understanding of the convolution process. During the convolution computation, we populate the filtering kernel into three identical dimensions to allow a single matrix multiplication for each pixel. By doing all three color channels at once, we can leverage the parallelism in Matlab to improve efficiency.
% Populate 3 copies of the filter to handle RGB calculations efficiently
kernel = repmat(filter, [1,1,imDims(3)]);
% Convolution in spatial domain
for i=1:imDims(1)
for j=1:imDims(2)
output(i, j, :) = sum(reshape(padImage(i:i+kerDimR-1, j:j+kerDimC-1, :) .* kernel, [], 3));
end
end
Gaussian filters are used to compute the filtered images used to construct the hybrid images. To make the algorithm more efficient, we take advantage of the fact that Gaussian filters are separable. Hence, we do two separate 1-d Gaussian filters to compute the low-pass filtered image. The high-pass filtered image can be obtained by removing the low frequency components of the original image.
The first two columns show the original images. The next two columns show the filtered images. Finally, the last column shows the resulting hybrid image.