Project 1: Image Filtering and Hybrid Images

A Hybridation of Einstein and Marilyn. A close Einstein and a far away Marilyn.

In this project, I write a my_imfilter function which aims to serve in the same way as Matlab's imfilter. Basically, it takes in two martrices and convolute them.

I make some decisions while constructing the algorithm. The first is to process color image layer by layer, say red, green, and bule.

The second is edge processing. Since convolution is basically a process that alters the pixel based on its neighbor pixels. However, those on the edge does not have neighbors all round, so I use padarray in 'symmetric' mode to reflect the border pixels and build the psudo-neighbors for the edges.

The third one is the convolution order. I choose to dot multiply the filter and the image pixel by pixel from upper left corner to down right corner. The alternative process is to build up row vectors, and concatenate vectors. My way to process the whole image is more intuitive.


Hybridization Process

The code snip aims to explain the hybridization process. Basically, the low frequencies of an image get to be combined with the high frequencies of the other image.


% generate low frequencies of both image    
low_frequencies = my_imfilter(image1, filter);
low_frequencies2 = my_imfilter(image2, filter);

% by substracting low frequencies, the high frequencies are remained
high_frequencies = image2 - low_frequencies2;

% re-construct am image with high and low frequenies from two different images
hybrid_image = low_frequencies + high_frequencies;


Some Other Results


Extra Credits: A Comparison

The following table exhibits the same filtering and hybrid algorithm applying on the same two images: cat and dog.

But they look so different.

The left one was generated using high frequency from dog while low frequency from cat, with a high frequency cut off rate at 12. The right one was generated using high frequency from cat while low frequency from dog, with a high frequency cut off rate at 9.

Frequency is a quite abstract concept. By comparing these two images, several conclusions about image frequencies can be drawn.

  1. Color infomation is mainly retained in low frequency. A Guassian blur filter smoothes the image, averages pixels with its neighbors, brings up intensity if low, and brings down intensity if high.
  2. An image of more thin edges needs a higher cut off threshold to remain the details. As observed, the dog with longer and more fur needs a higher cut off rate at 12 to look like a dog.
A comparsion like this reveals information; however, more study needs to be done on image frequencies to draw full conclusion.