CS 143 / Project 1 / Image Filtering and Hybrid Images

Image Filtering

For filtering, what I did initially was iterate over five things:

  1. Number of layers within the image
  2. Row index of the pixel
  3. Column index of the pixel
  4. Row index of the filter
  5. Column index of the filter

From there, at each pixel, I summed the neighboring pixels * the appropriate spots on the filter for a convolution-like effect. Unlike convolution though, I did not reverse the kernel/filter. Reversing it caused it to be slightly different from the imfilter functionality.

This was somewhat slow to do for multiple images. Thankfully, because MATLAB had special matrix handling, the for-loops were reduced down further to just the two for-loops responsible for iterating over the filter. This caused a nice sliding window effect of the filter on the image, reducing the computational time needed.


%example code
for j = 1:1:size(filter, 1)
    for k = 1:1:size(filter, 2)
        output(r,c,i) = 
		output(r, c, i) + filtered(r + j - filterDim(1) - 1 , c + k - filterDim(2) - 1, i) * filter(j, k);
    end
end

Hybrid Image Generation

With the support code, hybrid image generation was relatively simple to do! The low frequency image was produced through applying my image filter with Image A and the Gaussian filter. The high frequency image was produced by taking the low frequency version of Image B, and subtracting that from Image B. From there, the hybrid image was the sum of Image A's low frequency version and Image B's high frequency version. Yay!

As an example, here are the low frequency image of the dog image, the high frequency image of the cat image, and the hybrid image of these two.

The filter used was a Gaussian filter with a variable cutoff frequency. The filter size increases as the cutoff frequency increases. Originally, for the dog-cat hybrid image, the cutoff frequency was 7. Changing the cutoff frequency for some pairs was necessary to produce better hybridization.

Hybrid Image Generation

Here are some more examples of hybrid images, each tested with different cutoff frequencies of 1, 3, 5, and 7. The hybrid image with the best cutoff frequency is featured below the samples.

Marilyn Einstein - (r = 1, 3, 5, 7)

Based on the hybrid images, the Einstein-Marilyn image with cutoff frequency = 3 produced the best hybridization, because it could be shown as Marilyn with high resolutions and Einstein at low resolutions.

Subfish - (r = 1, 3, 5, 7)

Like the previous example, the Subfish image with cutoff frequency = 3 produced the best hybridization. The fish and the submarine can be distinctly seen at high and low resolutions, respectively.

Birdplane - (r = 1, 3, 5, 7)

While it didn't provide the clearest distinction, the Birdplane image with cutoff frequency = 5 produced the best hybridization out of all of the samples.

Motorbike - (r = 1, 3, 5, 7)

Like the previous example, the Motorbike image with cutoff frequency = 5 produced the best hybridization out of all of the samples, even if it didn't have the clearest distinction.

Yaayyyy ^M^