Ah, the first Automobile! Now take a few steps back, and have a look! Wait, is that a GLA?
The aim of this project is to create a hybrid image by combining two images, and filtering them for low and high frequencies. The high frequency image dominates the view when the hybrid image is looked at from a close distance, and the low frequency image dominates when the viewer moves far from the image. By combining these two filtered images, a hybrid image is obtained.
To perform the filtering of images, Matlab's inbuilt command 'imfilter' has been replicated in this assignment. The overall process followed to create a hybrid image:
%implementation of my_filter function
function output = my_imfilter(image, filter,type)
% 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)
type = 'zero';
end
%Calclate the row and column margin, to pad the input image
row_margin = (size(filter, 1) - 1) / 2;
col_margin = (size(filter, 2) - 1) / 2;
output = zeros(size(image));
%processing the input image
for ii = 1:size(image,3)
% pad the image array with zeros
if strcmp(type, 'zero')
input(:,:,ii) = padarray(image(:, :, ii), [row_margin col_margin]);
%pad the image array using the value of the nearby pixel
elseif strcmp(type, 'replicate')
input(:,:,ii) = padarray(image(:, :, ii), [row_margin col_margin], 'replicate');
end
end
%processing the output image
for ii = 1:size(image,3)
for jj = 1:size(input,1)-size(filter,1)+1
for kk = 1:size(input,2)-size(filter,2)+1
%Calculate the output by convoluting the image and the filter
output(jj,kk,ii) = sum(sum(filter.*input(jj:jj+size(filter,1)-1,kk:kk+size(filter,2)-1,ii)));
end
end
end
end
The example of a hybrid image, formed by merging a cat and a dog has been taken to illustrate the response to different filters, and the intermediate steps in the formation of a hybrid image.
For the rest of the image pairs, the input and output images alone are shown.
Identity Filter |
Small Blur |
Large Blur |
Sobel Filter |
Laplacian Filter |
High pass filter |
'Dog' - Removing the high frequencies |
'Cat' - Removing the low frequencies |
Hybrid Image |
Time taken to run my_imfilter |
Time taken to run imfilter |
There is a clear difference in the execution time between the inbuilt imfilter function and the looping statements written to replicate the function. One reason for this could be that, imfilter calls conv2 for convolution, which is a built=in matlab function, and is already pre compiled with the software. To minimize the looping statements, im2col and col2im functions were used. This reduced the two nested for loopes which were used previously to one. Surprisingly, the execution time results obtained with these commands show a even larger execution time.
|
'Motorcycle' - Removing the high frequencies |
'Bicycle' - Removing the low frequencies |
Hybrid Image |
'Bird' - Removing the high frequencies |
'Plane' - Removing the low frequencies |
Hybrid Image |
'Einstein' - Removing the high frequencies |
'Marilyn' - Removing the low frequencies |
Hybrid Image |
Below is an example of the hybrid images formed when different the images are filtered alternatively for high and low frequencies.
'Fish' - Removing the high frequencies |
'Submarine' - Removing the low frequencies |
Hybrid Image |
'Submarine' - Removing the high frequencies |
'Fish' - Removing the low frequencies |
Hybrid Image |
To try creating a hybrid image from a different set of images apart from the image pairs given for the assignment, the first car ever made and the Mercedes GLA were merged. Indeed, Mercedes has come a long way!!
'Mercedes-Benz GLA' - Removing the high frequencies |
'Three Wheeled Motorwagen' - Removing the low frequencies |
Hybrid Image |