Project 1: Image Filtering and Hybrid Images

Hybrid Image of Bird and Plane

The goal of this assignment is to write an image filtering function and use it to create hybrid images. These images are perceived in a different manner by human eyes depending on distance from the screen. The basic idea is that high frequency tends to dominate perception when it is available, but, at a distance, only the low frequency (smooth) part of the signal can be seen. Therefore, blending both high frequency part of one image and low frequency part of another image, we form an hybrid image. The two step process involved:

  1. Image Filtering: Obtain low pass and high pass filtered image of the two images respectively.

  2. Hybrid Image Formation: Add images with low and high frequencies to obtain hybrid image. Downsample images progressively to visualise the effect

The image on the right top of this page shows a hybrid image formed using a plane and a bird. Here, the low frequencies of plane are retained and added with the high frequencies of bird. The resultant hybrid image after addition is seen.

Algorithm and Implementation

  1. Image Filtering
    • The filter function: my_imfilter(image, filter) takes an image and filter as parameter and returns the low pass filtered output of the image being passed.
    • The image is convereted to double precision.
    • Output matrix is created to be same size as input image and the size of the filter is computed to perform padding.
    • Padding is done on both sides by mirroring the image. Here, the filter may not be a square and maybe a rectangle. Hence both dimensions of filter is considered while padding.
    • Filtering is done considering the three channels : RGB. On each of these components, pixel intensity is computed at each location. The computation is done by taking the dot product between the filter and input image and finally being added.
    • It is also vital to consider the output image and include only the dimensions of the input image by removing the extra padding taken for computation

  2. Hybrid Image Formation
    • The two input images are read. They are aligned perfectly so that they could be formed together to create a proper hybrid image.
    • The cut off frequency is varied depending on how the hybrid images are formed
    • A Gaussian filter is created using the Matlab's fspecial module
    • Low frequency of the first input image is obtained
    • High frequency image of the second input image is obtained by subtracting the low frequency component of the same image from the original image.
    • Adding the results of the previous two operations results in the formation of hybrid image

Results in a table

Image 1 - LPF Image 2 - HPF Hybrid Image = Image 1 + Image 2 Downsampling

The above shown are five pairs of hybrid images with their downsampled versions. For each pair, the high frequency image, low frequency component image is also shown. Different cut off frequency is used for different pairs. For Marilyn and Einstein it is kept to 3, whereas for fish and submarine its modified to 5. For others, it's kept at 7. The effect of both images being present in the hybrid image is seen clearly with downsampling.