Hybrid Image generated from two images, one of me and one of a wizard.
In this assignment we write an image filtering function and use it to create hybrid images.
my_imfilter
function output = my_imfilter(image, filter)
% We use the size of filter to calculate how many zeros we need to pad the input image with on each side
% This is half the dimension of the filter. We floor it to obtain an integer value
fsize = size(filter);
pad = floor(fsize/2);
imsize = size(image);
% We pad the image using the calculated value and the padarray function
paddedImg = padarray(image,pad);
% We initialize an empty output image
outImg = zeros(imsize,'single');
% In convolution we basically flip one of the signal before element wise multiplication with the other
% function and then add the result up
% Hence in the case of image/matrix this flip corresponds to a 180 degree rotation. We use rot90 twice.
rotfilt = rot90(rot90(filter));
% We iterate over each pixel of the image and do element wise multiplication. The padding takes care of
% the boundary cases
% We sum over the element wise multiplied matrix to obtain the value for that pixel. We repeat the
% process for as many channels as the image may have
for i = pad(1)+1:pad(1)+imsize(1)
for j = pad(2)+1:pad(2)+imsize(2)
if size(image,3) > 1
for k = 1:imsize(3)
outImg(i-pad(1),j-pad(2),k) = sum(sum(paddedImg(i-pad(1):i+pad(1),j-pad(2):j+pad(2),k).*rotfilt));
end
elseif size(image,3) == 1
outImg(i-pad(1),j-pad(2)) = sum(sum(paddedImg(i-pad(1):i+pad(1),j-pad(2):j+pad(2)).*rotfilt));
end
end
end
% We return the image
output = outImg;
my_imfilter
Input Image | Identity Image | Small blur with box filter | Large Gaussian blur |
Sobel filtered image | Discrete Laplacian filtered image | High pass "filter" |
low_frequencies = my_imfilter(image1,filter);
high_frequencies = image2 - my_imfilter(image2,filter);
hybrid_image = low_frequencies + high_frequencies;
The images that follow will adhere to the format below.
Input | Input | High Frequencies | Low Frequencies |
Hybrid Image at different scales |
Dog and Cat
Me and Harry Potter. Harry's image was obtained from here and appropriately cropped. Positioning was a challenge, as you can see.
Bicycle that aspires to be a motorcyle
The Tuna Sub (not sure if this fish is actually Tuna. All is fair in the search of funny titles though)
Its a plane, no it's a bird... (but certainly not Superman)
If you look closely, you can see Ms. Monroe donning a tie