Project 1: Image Filtering and Hybrid Images

Example of a gaussian filter.

In this assignement our task was to write the Matlab function my_imfilter which mimicks the behavior of the imfilter function. The goal of the assignement is to illustrate the idea of filtering at a pixel level. The use of padding for the images was required so that the output of the function would have the same size as the input image. The filtering function is required to work with greyscale and color images. Finally a demonstration of the function is required, with visualization of the output images. A small note is that we realize that in Matlab the vertical dimension y is indexed in the first position of an array as follows: array(y,x). We use the inverse throughout our code and project essay but it does not change the results or the validity of the code because we are essentially just changing the names of the variables.

Image Padding

Image padding is required so that the output image has the same size as the input image. There are several ways to pad an image and two of these alternatives have been explored in our work. One way is to pad the image borders with zeros and the other one is to pad the image with reflections of the border values. The final project uses the second alternative. The padding is done with the Matlab function padarray. We started writing and almost finished a padarray function from scratch but we then realized that the use of the Matlab padarray function was authorized. The idea of the function is simple: to copy the image into the center of an array of size [x_image + 2 * x_padding, y_image + 2 * y_padding] and then to loop around the edges and replacing the pixels by zeros or reflections of the image.

Filtering

The filter function is simple to write as a double for loop. We initialize an array padded_img of size [x_size_of_img, y_size_of_img] and then for every pixel we compute the corresponding Hadamard product of the padded image and the filter. We have to distinguish the two cases of the greyscale image and the color image. The difference between these cases is that in the former one we only compute the filtering for one depth dimension and for the latter we compute it for the three RGB color dimensions.

Testing

The testing is done with the supplied script which computes different convolutions with gaussian filters on a kitten image using our my_imfilter function. We have some blurred images and some high-frequency images as output.

Demo

For the demo we started by filtering the cat-dog image by using the cat image as the high-frequency and the dog image as the low-frequency as is done in the project webpage for comparison purposes. We used the cutoff-frequency standard deviation value (in pixels) of 7 (the same for both images). We computed the high-frequencies by applying the gaussian filter to the cat image and then by substracting this blurred image from the original cat image. The low-frequency image is obtained by filtering the image with the gaussian blur filter. We then summed the pixel values of these pictures to obtain the hybrid image. Both of the components of the hybrid image can be seen in the following figures. The resulting cat-dog hybrid image is very similar to the one in the project page so we can conclude that the my_imfilter function is a success.

We built our own example image using an image from an Orangutan and a picture of Presidential Republican candidate Donald J. Trump following a joke from the Bill Mahr show where Trump's hair is compared to an Orangutan's hair. The results may be humorous for some, but we take this experiment with utmost seriousness. We also built an example of what would happen if you combine an albino gorilla with a shaved albino gorilla (Brock Lesnar from WWE). Finally we demonstrate that there is a potential for stylistic and artistic effects using this technique. We combined a landsacape portraying Bolivia's most famous mountain peak, the Illimani, with a picture of fire.

One final interesting application that might be possible is to merge a high frequency pattern and letters so that the letters are hidden by the pattern at close distance but are revealed when the subject is far away. This might be interesting in psychology experiments where one would want to reveal stimuli gradually. One way of doing this would be to use the full sized image and then shrink the image as time goes by.