Project 1: Image Filtering and Hybrid Images

I. Image Filtering

Given an image, the appearance of the image can be modified using various filters. In this project, the image filtering function in MATLAB has been implemented so that some provided filters can be applied to the images. The two inputs are an image and one of any arbitrarily shaped filters that have odd numbers as dimensions. The output will be a modified version of the original image. Here are the filters applied onto a cat image.

Large blur filter without zero-padding

  1. Original image
  2. Identity filter
  3. Small blur box filter
  4. Large blur line filter
  5. Oriented filter(Sobel operator)
  6. High pass filter(Discrete Laplacian)
  7. High pass alternative

With a matrix of values representing the image, the filters were applied by multiplying the filter values to every pixel and its surrounding pixels as well, then adding the values. But in order to apply the filter to every single pixel of the image, the image is padded with zeros beforehand so that the filters do not go out of bounds of the matrix.


for k=1:3
    for i=m+1:s(1)+m-1
        for j=n+1:s(2)+n-1
            temp = image(i-((m-1)/2):i+((m-1)/2),j-((n-1)/2):j+((n-1)/2),k) .* filter;
            r(i-m,j-n,k) = sum(temp(:));
        

In code, k represents the 3 RGB color channels of the image, i and j represents the row and column of the image matrix respectively. The for-loop iterating through the image pixels start m or n distance away from the first pixel because the image matrix has already been padded with zeros.

II. Hybrid Images

High frequency image of fish

Low frequency image of submarine

Hybrid image generated from submarine and fish

In order to generate a single hybrid image using two input images, the high frequency component of one image and the low frequency component of the other image are extracted. Then the two filtered images are combined to form a hybrid image that shows both images depending on how far you are, or the size of the generated image. The low frequencies of the image can be extracted by applying a Gaussian blur filter, whereas high frequencies of the image can be extracted by subtracting the low frequencies from the original image.