Project 1: Image Filtering and Hybrid Images

Hybrid images are generated by superimposing two images at two different spatial scales: the low-spatial scale is obtained by filtering one image with a low-pass filter; the high spatial scale is obtained by filtering a second image with a high-pass filter. The final image is composed by adding these two filtered images.

The basic steps of combining two image are:

  1. filter image 1 with low-pass filter
  2. filter image 2 with high-pass filter
  3. simply add image 1 and image 2 to get hybrid image

Filter image with neighborhood operator

The most commonly used type of neighborhood operator is a linear filter, in which an output pixel's value is determined as a weighted sum of input pixel values

$$ g(i, j) =\sum_{k, l}f(i + k, j + k)h(k, l) $$

In the boundary, the input image is padded with zeros

Example of code with highlighting

Instead of using a loop to calculate the weighted sum, we can use sum of dot product for matrix.

Since grayscale and color images have different dimensions, we need to deal with them separately.


%example code
if(length(imageSize) == 2)
    image = padarray(image, (filterSize - [1, 1]) / 2);
    n = imageSize(1); m = imageSize(2);
    for i = 1 : n
        for j = 1 : m
            output(i, j) = sum(dot(image(i : i + filterSize1 - 1, j : j + filterSize2 - 1), filter));
        end
    end
else
    image = padarray(image, [(filterSize - [1, 1]) / 2, 0]);
    n = imageSize(1); m = imageSize(2); l = imageSize(3);
    for i = 1 : n
        for j = 1 : m
            for k = 1 : l
                output(i, j, k) = sum(dot(image(i : i + filterSize1 - 1, j : j + filterSize2 - 1, k), filter));
            end
        end
    end
en

Results

As we can seen, if we look at the hybrid image at a close distance, we perceive the picture as plane and fish, which are high frequency component of the hybrid images. But if we scale down the hybrid image, we can see small bird and submarine at a far distance.