Project 1: Image Filtering and Hybrid Images

Filtering Algorithm

For this project, the ideas of image filtering and hybrid image creation were explored. A basic algorithm for filtering images was written based on the built-in function 'imfilter' in MATLAB. The algorithm first adds a buffer of zeros around an inputted image array, as shown below:

[r, c] = size(filter);
[row,col,layer] = size(image);
tmp = single(zeros(row+r-1,col+c-1,layer));
rBound = floor(r/2);
cBound = floor(c/2);
tmp(rBound+1:row+rBound,cBound+1:col+cBound,:) = image;
image = tmp;

where 'image' is the image array and 'filter' is the filter to be used. After buffering the image to ensure the filter will not index out-of-bounds, the filter is then applied simply using three nested for loops. The remainder of the algorithm is shown below.

output = single(zeros(row, col, layer));
for k = 1:layer
  for i = 1:row
    for j = 1:col
      section = image(i:i+r-1, j:j+c-1,k);
      section = filter .* section;
      output(i,j,k) = sum(section(:));
    end
  end
end

The below table displays the results of image filtering using this algorithm. From left to right, the images and filters are as follows: original image, image with Gaussian blur applied, image with Sobel filter applied, and image with a Laplacian high-pass filter applied. Note that the last two images were edited to be better viewed, as the images directly after filtering were mostly black. One can also see the effect of using a zero buffer within the filter application algorithm clearly in the second image, where the border is slightly darkened.




Hybrid Images

A number of hybrid images were then produced using the custom filtering function. To create these images, the high-pass filtered version of one image is combined with the low-pass filtered version of a second image (note that low-pass filtering is the same as blurring). This creates an image with different appearances based on the distance from which the image is viewed. A series of example images are shown below, demonstrating low-pass filtered image and high-pass filtered image on the left and right, respectively. In creating these images, a cutoff frequency was used to control the amount of blur and adjust the prominence of the high-pass filtered image in the final hybrid image.

The high-pass and low-pass filtered images are combined and shown below as a hybrid image. As the image gets smaller, the low-pass filtered image is more visible. One can see the submarine fairly clearly by the second to last image.