Project 1: Image Filtering and Hybrid Images

Algorithm
We first pad the original image with zeros. Then we do a double for-loop to iterate through the image using the filter's boundaries. The resulting sub-matrix's and the filter's dot product will be placed in the corresponding cell in the returning marix. The last for-loop is just iterating the number of layers in the matrices and placed the corresponding dot product in the cell that would correspond to the red, green and blue matrix. The resulting matrix will then be returned. The algorithm was chosen because it gives an O(n2) + O(k) runtime which is equivalent to O(n2).


Code

Hover over for Description!

rgb_image = size(image, 3);

matrix = zeros(size(image, 1), size(image, 2), rgb_image);


zero_rows_needed = floor(size(filter, 1) / 2);

zero_row = zeros(zero_rows_needed, size(image, 2), rgb_image);

image = [zero_row; image; zero_row];


zero_cols_needed = floor(size(filter, 2) / 2);

zero_col = zeros(size(image, 1), zero_cols_needed, rgb_image);

image = [zero_col image zero_col];


row_length_image = size(image, 1);

col_length_image = size(image, 2);

row_length_filter = size(filter, 1);

col_length_filter = size(filter, 2);


row = 1;

col = 1;


for i = 1:(row_length_image - row_length_filter + 1)

for j = 1:(col_length_image - col_length_filter + 1)

for k = 1:rgb_image

dot_product = sum(sum(image(i:(i+row_length_filter - 1), j:(j + col_length_filter - 1), k) .* filter));

matrix(row, col, k) = dot_product;

end;
col = col + 1;

end;
row = row + 1;

col = 1;

end;
output = matrix;


Filtering Results

Original Image












Identity Filtered Image
Small Blur Filtered Image
Large Blur Filtered Image
Oriented Filtered Image
High Pass Filtered Image
High Pass Alt Filtered Image


Hybrid Results

cutoff_frequency = 7

Original Photo
Original Photo












Low Frequencies
High Frequencies
Hybrid Image
Hybrid Image Scales























cutoff_frequency = 2

Original Photo
Original Photo












Low Frequencies
High Frequencies
Hybrid Image
Hybrid Image Scales























cutoff_frequency = 5

Original Photo
Original Photo












Low Frequencies
High Frequencies
Hybrid Image
Hybrid Image Scales