Project 1: Image Filtering and Hybrid Images

For this project, imfilter() was replicated as my_imfilter(). This function applies a given filter to an image to create a new image. Filtering works by assigning a pixel in an output image a value by weighting the values of that same pixel and surrounding pixels in the input image.

Algorithm Implementation

The implementation of my_imfilter() is simple, but literal edge cases occur when the target pixel is so close to the edge of the image that surrounding pixels needed by the filter do not exist. To solve this issue, the original image is 'reflected' over the boundary to supply the filter with sufficient information. Pseudocode describing the algorithm and corresponding Matlab code are shown below, respectively:

      
let F := the filter
let I := the input image
let O := the output image of the same size as I

for each color in I:
  for each row in I:
    for each column in I:
      O[row, col, channel] <- F·I[row, col, channel]

return O










      
    

Filtering pseudocode.

      
filter_size = size(filter);
pad_size = (filter_size - 1) / 2;
padded_image = padarray(image, pad_size, ...
                        'symmetric', 'both');
img_size = size(image);
output = zeros(img_size);

for channel = 1 : img_size(3)
  for row = 1 : img_size(1)
    for col = 1 : img_size(2)
      pixels_in_filter = padded_image( ...
          row : row + (2 * pad_size(1)), ...
          col : col + (2 * pad_size(2)), ...
          channel ...
        ).*filter;
      output(row, col, channel) = ...
        sum(sum(pixels_in_filter));
    end
  end
end
      
    

Matlab implementation of filtering.

Results

For each set of pictures shown below, three components are included, respectively: one image processed with a high pass filter, a progression of the hybrid image which illustrates high vs. low pass at each scale, and an image processed with a low pass filter. The hybrid image is a combination of the high pass-filtered image and the low-pass filtered image. Note that as the size of the hybrid image decreases, the image seems to transform from the left-most picture in the set to the right-most picture in the set.

Bicycle to Motorcycle

Bird to Airplane

Cat to Dog

Marilyn to Albert

Fish to Submarine