Project 1: Image Filtering and Hybrid Images

Example of a hybrid image.

Introduction

In this project,we need to implement our own image filter function that performs similar to the built-in imfilter() function. Based on the image filter, we construct a series of hyrbid images by combining low frequencies of one image and high frequencies of another image.

Some details about my algorithm

Basically, I use the for loop on each individual color channel to write my_imfilter function because I think this is the most straight forward way to do this.The first step I do is to pad the original image by 0 (there are other methods of padding, but this is the easiest way), I use the built-in padarray function, which gives me a nice padded matrix to begin with. The second step is to create an empty matrix that has same size as the input image.This way we can ensure that we have the correct dimension of the output image, and don't need to delete rows or columns later. Then I do the multiplication and addition to fill out the empty matrix by using for loop. The idea behind the multiplication and addition is the formula: g(i,j) = sum(f(i+k,j+l)*h(k,l)), where f is our input image, h is our filter.Repeat the multiplication and addition for other 2 color channels.Finally, after the for loop is done, output the matrix.

To construct the hybrid image, use my_imfilter function to blur first image in order to remove high frequencies, then remove the low frequencies from second image by subtracting a blurrd second image. Then we add these 2 modified images together using matrix addition, this will give us the hybrid image we want.

Results of my algorithm

Results of filtering

The images in first row, from left to right, are: test image(the original image),identity image(this should be identical to the test_image), blur image and large blur image. The images in second row, from left to right, are: sobel image, laplacian image and high pass image. The results from my_imfilter looks the same as those from MATLAB's built-in imfilter function.

Results of hybrid images

These are some intermediate images and final results of hybrid images.We need to tune the cut-off frequency for each set of images. The cut_off frequency I use for each set of images are: cat&dog 7, fish&submarine 6, Marilyn&Einstein 2.5, plane&bird 4.5, bicycle&motorcycle 7, Jobs&Cook 3. I think the result images look pretty good.

Extra Credit

For this project, I also implement the seperable filtering in my_imfilter function.For every input filter, first check if the filter can be seperated into 2 one-dimensional matrices.(According to our textbook, if the first singular value of kernel is non-zero, the kernel is sperable(Perona 1995)). If the filter is seperable, compute the vertical and horizontal filter. Then apply the vertical and horizontal one-dimensional filter seperately to the image using similar for loop method in non-seperable case. In addition to seperable filting, I choose a different pair of images to construct my own hybrid image(Jobs and Cook).