Project 1: Image Filtering and Hybrid Images

The algorithm is just a straight-up implementation of the filtering formula.

  
    [M, N, C] = size(image);
    [m, n] = size(filter);
    xpadding = (m - 1) / 2;
    ypadding = (n - 1) / 2;
    padded = padarray(image, [xpadding, ypadding]);
    output = zeros(M, N, C);

    for c = 1:C
        for i = 1:M
            for j = 1:N
                output(i, j, c) = sum(sum(padded(i:(i + m - 1), j:(j + n - 1), c) .* filter));
            end
        end
    end
  
  1. Create a zero padded version of the image
  2. Create a zero matrix of the same size as the original image to hold the result
  3. For each color channel
    1. Iterate over every pixel of the output
    2. Compute the total sum of the Schur product of the filter and a slice of the padded image
The hybrid image creation selects the low frequencies of one image and the high frequencies of the other and then computes their mean.

Low- and High-Frequency Images

Low frequencies of the dog picture

High frequencies of the cat picture

Hybrid Image Examples

Hybrid image of a cat and a dog (𝞼 = 7)

Hybrid image of Einstein and Marilyn Monrow (𝞼 = 5). Here I had to replace the mean with a weighted sum and give a higher weight to Marilyn Monroe, because otherwise she was overshadowed by sharp Einstein (65% Monroe, 35% Einstein).

Hybrid image of a submarine and a fish (𝞼 = 5). This one required a weight sum as well (60% submarine, 40% fish).

Hybrid image of a bird and a plane (𝞼 = 7)

Hybrid image of a bicycle and a motorcycle (𝞼 = 5)

To get reasonable results you have to experiment with the order of the pictures, i.e. which to take the high and which to take the low frequencies from, as well as the width of the Gaussian blur filter and the weighting when combining the parts into a hybrid image.

My Own Hybrid Image

Hybrid image of me and my girlfriend (𝞼 = 7)