Project 1: Image Filtering and Hybrid Images

Example of a hybrid image. The image is perceived as a dog if the viewing distance is large enough.

In project 1 linear filtering is implemented and used to on images to achieve blurring effects. Two separate images are filtered so that one only shows the high frequency and the other only shows the low frequency signals. The two images are then overlayed to create a hybrid image that changes perception with increases in viewing distance. An example of the hybrid images is shown to the right.

Depending on the filters that are used, other effects can include sharpening, edge detection, remove noise, etc. Below are some examples of the common filters:

  1. Identity
  2. High pass
  3. Laplacian
  4. Sobel
  5. Blur
  6. Gaussian Blur

A function for applying filters is written in MATLAB. The function takes in an image( grayscale or color ) and a filter with odd width and height and outputs a filtered image of the same size. Below is the sample code for the filtering process on a given image.

my_imfilter


%my_imfilter

i = size(image); %[row, column, channel]
fr = floor(f(1)/2); %# of row padding on each side
fc = floor(f(2)/2); %# of column padding on each side
output = zeros(size(image));
for ch=1:i(3)
    mImage = image(:,:,ch);
    %Pad fr rows and fc columns to each channel of the image
    mImage = padarray(mImage,[fr, fc]); 
    for r=1+fr:i(1)+fr
        for c=1+fc:i(2)+fc
            out = mImage(r-fr:r+fr,c-fc:c+fc) .* filter;
            output(r-fr,c-fc,ch) = sum(out(:));
        end
    end
end;

The function first finds how much padding is required for the input image based on the filter size. The padding is required so that the behavior around the edges of the input images are defined. The padding in each direction is defined as the floor of size of the filter in the same direction divided by 2. As an example, if the filter has a size of 3 x 5, then padding will be floor(3 / 2) = 1 row and floor( 5 / 2) = 2 columns on each side. The resulting padded image will be (r + 1*2 ) by (c + 2 * 2). With the padded image, for each pixel a matrix of the same size as the filter surrounding the pixel will be dot multiplied with the filter to be stored as the resulting value of the filter.

All the example filters listed above are applied to the same cat image and the results are shown below.

Filter Results

Identity
High Pass
Laplacian
Sobel
Blur
Gaussian Blur

Hybrid Images

To create a hybrid image, 2 ordinary images(preferrably of the same size) is needed. The visual effects work better if the two pictures are aligned well.

The first image is blurred using a guassian filter which will result the following image:

This effectively act as a low pass filter and removes the high frequency signal from the image.

The second image is then blurred using a guassian filter and the result is subtracted from the unfiltered image which will result the following image:

The two filterd images are then combined into one to give the appearance of Donald Trump when close up but an orangutan when farther away. The hybrid image of Trump and orangutan as well as other hybrid images made are shown below.

Trump and orangutan

Einstein and Marilyn

Submarine and fish

Motorcycle and bicycle

Trump and Clinton

Legal Disclaimer

The combintaions of two images are not proof, suggestion or intimation that the subjects of the pictures are related in any way or form. The hybrid images are for entertainment only.