In this project, I need to write an own image filtering function "my_imfilter" which is similar to the build-in fuction imfilter(). And then I need to use my_imfilter() to create a hybrid_image that is combined by two different images. Hybrid_image leads to different interpretations at different distances.
Function my_imfilter takes two parameters- image and filter. The image is a matrix of different numbers as well as filter. The main principle of this function is we take each pixel and the pixels around it product the filter and sum the numbers together. Then we put the sum of the product to a same size image at the same position as the pixel we take. The problem I meet in this function is that there are some pixels missing when we process the pixels of the image in the edge because filter extend the edge of the image. We have severl ways to handle this problem such as 'circular', 'replicate', 'symmetric' and I chose the symmetric method.
function output = my_imfilter(image, filter)
[row, col, channel] = size(image);
[fil_row, fil_col] = size(filter);
padding_row = (fil_row - 1) / 2;
padding_col = (fil_col - 1) / 2;
padded = padarray(image, [padding_row, padding_col],'symmetric');
output=zeros(size(image));
for i = 1:row
for j = 1:col
for k=1:channel
output(i,j,k)=sum(sum(padded(i:i+fil_row-1,j:j+fil_col-1,k).*filter));
end
end
end
To process a hybrid image we need to get two images as parameter and then use
low_frequencies = my_imfilter(image1, filter);
to get the low frequency of image 1 which is dog.bmp in our data folder. Then we use high_frequencies = image2 - my_imfilter(image2, filter);
to get the high frequency image of image2 which is cat.bmp in data folder. At the end, add low and high frequency images together using hybrid_image = low_frequencies + high_frequencies;