An example of a processed hybrid image.
This project's goal is to write an image filter processing function in Matlab to create hybrid images which combine two different images by applying low-frequency and high-frequency filters respectively. As a result, you get a hybrid image that at a close distance, the high frequecny filtered image becomes more salient and at a longer distance, the low frequecny filter image becomes visible.
Although, Matlab's own 'imfilter' function works flawlessly with GPU and 64 bit accerlation support, the goal of the project is to design own filter algorithms to get acquainted with Matlab functions. The example of an hybrid image is shown on the right. If you step further away and view the image, the high pass filtered 'cat' image will fade away and be able to see the low-pass filtered image.
low_frequencies = my_imfilter(image1, filter, 'mirror');
high_frequencies = image2 - my_imfilter(image2, filter, 'mirror');
hybrid_image = low_frequencies + high_frequencies;
Code using two different frequencies for low and high pass filters.
%% Filtering and Hybrid Image construction
cutoff_frequency = 7;
cutoff_frequency2 = 2;
filter = fspecial('Gaussian', cutoff_frequency*4+1, cutoff_frequency);
filter2 = fspecial('Gaussian', cutoff_frequency2*4+1, cutoff_frequency2);
low_frequencies = my_imfilter(image1, filter, 'mirror');
high_frequencies = image2 - my_imfilter(image2, filter2, 'mirror');
hybrid_image = low_frequencies + high_frequencies;
For the filter implmentation, as suggested in the homework description, I used 'padarray', 'im2col', and 'col2im' functions in Matlab. It can support the following features.
% Handles the cases where the filter sizes are not given as odd numbers
if (~mod(size(filter, 1), 2) || ~mod(size(filter, 2), 2))
error('The row and column size of the filter have to be in odd numbers.');
end
% The default option is padding with zeros
if (nargin < 3)
option = 'zero';
end
r_margin = (size(filter, 1) - 1) / 2;
c_margin = (size(filter, 2) - 1) / 2;
result = zeros(size(image));
for ii = 1:size(image,3)
% pad the image array either symmetrically or with zeros
if strcmp(option, 'zero')
input = padarray(image(:, :, ii), [r_margin c_margin]);
elseif strcmp(option, 'mirror')
input = padarray(image(:, :, ii), [r_margin c_margin], 'symmetric');
end
% calculate the filter using im2col, col2im, and dot product
filtered = filter(:)'*im2col(input, size(filter), 'sliding');
result(:,:,ii) = col2im(filtered, [1 1], [size(image, 1) size(image, 2)]);
end
output = result;
![]() Identiy |
![]() Small Blur |
![]() Large Blur |
![]() Large Blur w/ symmetrical (mirrored) padding |
![]() Sobel |
![]() High Pass (discrete Laplacian) |
![]() High Pass (alternative) |
![]() 'Dog' image w/ low frequencies |
![]() 'Cat' image w/ high frequencies |
![]() Hybrid Image |
![]() |
![]() 'Bird' image w/ low frequencies |
![]() 'Plane' image w/ high frequencies |
![]() Hybrid Image |
![]() |
![]() 'Bird' image w/ low frequencies |
![]() 'Plane' image w/ high frequencies |
![]() Hybrid Image |
![]() |
![]() 'Plane' image w/ low frequencies |
![]() 'Bird' image w/ high frequencies |
![]() Hybrid Image |
![]() |
![]() 'Einstein' image w/ low frequencies |
![]() 'Marilyn' image w/ high frequencies |
![]() Hybrid Image |
![]() |
When the cut frequency gets smaller, Einstein appears quicker as smaller the image becomes. But, You can still see Marilyn in the third image.
![]() 'Einstein' image w/ low frequencies |
![]() 'Marilyn' image w/ high frequencies |
![]() Hybrid Image |
![]() |
When the cut frequency 2 gets smaller, Marilyn disappears quicker as smaller the image becomes. In the third image, you can see Einstein better
![]() 'Einstein' image w/ low frequencies |
![]() 'Marilyn' image w/ high frequencies |
![]() Hybrid Image |
![]() |
![]() 'Motorcycle' image w/ low frequencies |
![]() 'Bicycle' image w/ high frequencies |
![]() Hybrid Image |
![]() |
![]() 'Motorcycle' image w/ low frequencies |
![]() 'Bicycle' image w/ high frequencies |
![]() Hybrid Image |
![]() |
![]() 'Bicycle' image w/ low frequencies |
![]() 'Motorcycle' image w/ high frequencies |
![]() Hybrid Image |
![]() |
![]() 'Fish' image w/ low frequencies |
![]() 'Submarine' image w/ high frequencies |
![]() Hybrid Image |
![]() |
![]() 'Submarine' image w/ low frequencies |
![]() 'Fish' image w/ high frequencies |
![]() Hybrid Image |
![]() |