CS 143 / Project 1 / Image Filtering and Hybrid Images

In this project, we are aiming to hybrid two images, so that the large scale of the result looks like the first input image while the small scale of the result looks like the other.

Hybrid Image

The algorithm takes in two images as input. The content of the image should be similar enough to each other and some of the significant features should be lined up. This is very essential to the quality of the final result. The stencil code generates a gaussian filter based on a standard deviation, which can be adjusted according to the input images. Then both input images are convolved with the gaussian filter and get the low frequencies of image1 and image2: image1' and image2'. Subtract image2' from image2 and get the high frequencies of image2: image2". The final step is simply add image1' and image2" together to generate the hybrid image.

Image Filtering

Before I convolve the filter with the image, I padded the image with n rows and n colomns of 0s, where n=(number of rows in the filter)/2+1600. Starting from (n+1, n+1), the value of the filtered image at that pixel is the dot product of the neighbours of the pixel and the filter.

Parameter

Here is a list of the standard deviation value I used for each test case, and which image contributes the low frequencies or high frequencies.

  1. standard deviation:7; Low frequencies: dog.bmp; High frequencies: cat.bmp.
  2. standard deviation:12; Low frequencies: bicycle.bmp; High frequencies: motorcycle.bmp.
  3. standard deviation:7; Low frequencies: bird.bmp; High frequencies: plane.bmp.
  4. standard deviation:6; Low frequencies: marilyn.bmp; High frequencies: einstein.bmp.
  5. standard deviation:6; Low frequencies: submarine.bmp; High frequencies: fish.bmp.
  6. standard deviation:8; Low frequencies: cry.bmp; High frequencies: smilebaby.bmp.
  7. standard deviation:2; Low frequencies: smilebaby.bmp; High frequencies: cry.bmp.

Results

The last two rows were generated from the images I took from google image search. One input is a crying baby and the other one is a smiling baby. Images are shown below:

Discussion

In order to get a fairly ideal result, the two input images should be aligned. For example, in the cat and dog test case, their eyes were aligned; in the test case 6 and 7, the eyes of two babies were aligned, because the luminance of the eyes are so dark that after filtering they are still very dark, and will ruin the result. The test case of bicycle and motocycle does not work very well. No matter what value I assign to the standard deviation, the bicycle are still very obvious. I also tried to take the high frequencies from the motorcycle and the low frequencies from the bicycle, but the result is still not ideal because they are not aligned perfectly.