CS 143 / Project 1 / Image Filtering and Hybrid Images

A sample hybrid image using my_imfilter implementation.

1. The Goals of the Project

There are two main goals of this project:

  1. Implementing convolution operation with automatic image padding support.
  2. Using implemented convolution API to generate hybrid images.

2. My Work

  1. Implemented imfilter() interface in Matlab.
  2. Implemented hybrid image algorithm.
  3. Tested hybrid image algorithm on several datasets.

3. Implementation

3.1 Convolution and my_imfilter implementaion.

The implementaion of imfilter is quite straightforward. The API accepts two parameters:image and filter. The function does its work in following steps:

  1. Padding the image with black areas depending on the size of filter.
  2. For each level of the image and for each pixel on that level (not including the padded part), doing convolution operation with the given filter.
  3. Storing the results to an output image with the size which equals to the input image and has the same number of channels.
  4. Returning the output image.

Within the above steps, the most important one is to do the convolution for each pixels in the image. The code goes like this:


%Code doing convolution.
for l = 1 : size(image, 3)
    %do convolution on padded channel
    for i = startRow : endRow
        for j = startCol : endCol
            convolution = 0.0;
            for r = 1 : filterHeight 
                for c = 1 : filterWidth
                    convolution = convolution + ...
                        filter(r,c) * paddedImage(i - halfFilterHeight + r - 1,...
                        j - halfFilterWidth + c - 1, l);
                end
            end
            %set the convolution result to that pixel
            output(i - startRow + 1, j - startCol + 1, l) = convolution;
        end
    end
end

3.2 Hybrid Image Generation

With the help of imfilter(), making an hybrid image from two input images if rather straightforward. The steps are:

  1. Reading two input images, one for highpass filtering and the other for lowpass filtering.
  2. Making an Gaussian blur filter by fspecial() call with a cutoff frequency (this might vary).
  3. Get low frequencies of one image using my imfilter and the Gaussian blur filter.
  4. Get high frequencies of another image basing on my imfilter and the Gaussian blur filter.
  5. Adding the previous two results to get the hybrid image.

4. Experiments

4.1 My imfilter() Experiments

The following table of images is the results of implemented imfilter(). For each row, they are original image, average blurred image, Gaussion blurred image, Sobel image, Laplacian image and High pass filtered image.

Convolution Results

4.2 Hybrid Images

Using the given datasets, I was able to test the hybrid image genreation algorithm on them. The following part are the some hybrid images I got, and I also listed the cutoff fequency which has the best effect.

Hybrid Images
Cutoff Frequency = 7
Cutoff Frequency = 5
Cutoff Frequency = 4
Cutoff Frequency = 4
Cutoff Frequency = 3