This script show cases self implemented filtering functions, and uses them to create example cases of hybrid images.
Part 1 - Image Filtering
Here I create 2 filtering functions that behaves exactly the same way as the MATLAB built in function imfilter. One implementation is in real space, the other in fourier space.
Real Space Filtering
Filtering (or Convolution) can be written as an inner product of a partial Circulant matrix
and a filter vector
. This code exploits this formulation by calculating individual rows of
(which correspond to shifts of the image) and multiplying them with the scalar element of the filter that corresponds to that shift.
Fourier Space Filtering
Any circulant matrix
can be diagonalized by the Fourier matrix F as:
This fact can be exploited to achieve multiplication of a vector with
in O(nlogn) time using FFT. The following scheme can be used for this purpose, where
is the first column
and
is a vector containing the main diagonal of
:
where
is element-wise multiplication. Notice the above algortihm is actually the Convolution Theorem in disguise, where
is the Fourier Transform operator:
The mirror mismatch between convolution and correlation operations can be accounted for by conjugation of the filter in Fourier space.
Testing Accuracy and Performance
Let us load a test image first.
First lets us see if our functions are accurate by comparing them with the output from imfilter.
Now we can compare the speed of the 3 functions on a big image. The church image is 20 megapixels. Keep in mind that while the performance of MATLAB built-in function and real space implementation greatly deteriorates with larger filters, the Fourier space implementation only depends on the image size.
Example Filtering Cases
Identity Filter
Small Blur Filter
Large Blur Filter - Exploit Seperability
Sobel Filter
High Pass Filter
Part 2 - Hybrid Images
Hybrid images are created by melding the high frequency component of one image with the low frequency component of another. The images need to be aligned well for the product to be attractive.