Convolution is the process of multiplying every element in an image with some linear combination of its neighbors, where this combination is determined by some (smaller) kernel, or matrix, and this process is a fundamental component of image processing and computer vision. In this project, I was asked to implement a custom version of MATLAB's imfilter function, which filters a given image with some given filter or kernel. In my implementation, for each element in the matrix and for some m-by-n filter, I created a sub-matrix of m-by-n centered around the element and used MATLAB's fast element-wise multiplication operation, .*, on the sub-matrix and filter. I then utilized the sum of the resulting matrix to determine the new value of each respective element in the new filtered image. This method produced relatively fast code, and with proper preallocation of new matrices used in the implementation, the code ran significantly faster than a 4-5 for-loop implementation. The meat of the aforementioned convolution code is shown below:
% Pad image with mirror of itself
p_image = padarray(image, padding, 'symmetric');
% Allocate for size of filtered image so there's no memory re-initialization/fragmentation
f_image = zeros(size(image));
for x = padding(1) + 1:size(p_image, 1) - padding(1)
for y = padding(2) + 1:size(p_image, 2) - padding(2)
for channel = 1:size(p_image, 3)
pixel = p_image(...
x - padding(1):x + padding(1), ...
y - padding(2):y + padding(2), ...
channel) .* filter;
f_image(x - padding(1), y - padding(2), channel) = sum(pixel(:));
end
end
end
Below are some results from the proj1_test_filtering on bicycle.bmp. From left to right:
|
A hybridization of Marilyn Monroe and Albert Einstein at different scales.
Hybridization, in this assignment, is defined as the combination of the low frequencies from some image1 and the high frequencies from some other image2. One of the resulting visual effects is from different distances, the images will look different. This is a result of how human vision works. When a human views something at a large distance, the human brain effectively performs subsampling and changes the dominant frequencies that the brain perceives. As a result, when the human's' dominant frequencies cross over the cutoff frequency of the hybridization, then the human will see a different image.
Below are some other results from hybridization. Can you guess what they are?
|
dogs > cats)