Project 1: Image Filtering and Hybrid Images

Cat and Dog Hybrid Image.

For this project we were tasked with writing an algorithm in matlab that would perform image filtering given an image and an odd dimensional kernel. Having already done a similar project to this using python with numpy I was able to do the same general algorithm as before; however, matlab was more limited in what I could do in the creation of a Matrix. Matlab doesn't have anything similar to Python's list comprehensions so I had to adjust my original algorithm.

my_imagefilter

For this algorithm I first attempted to do all 3 channels at once through hard coding; however, I realized that we may be given grayscale images which would cause my algorithm to fail. Then I tried looping over all three color channels in the innermost part of the loop; however, this caused a weird error that made the picture look yellow. Then I decided to dod the simplest thing possible and just looped over the color channels followed by looping through each pixel. At the beginning I pad the image with zeros based on the size of the filter. The for each pixel I do a hadamard product between the filter and pixels surrounding the pixel I want. I then do a double sum over the resulting matrix to get the value for the corresponding pixel in my filtered image.


output(i,j,k) = sum(sum(image(i:i+2*xPad, j:j+2*yPad, k).*filter));

Hybrid Image Creation

The creation of the hybrid image was fairly simple the low frequencies were just a blurred version of the image. The high frequencies were created by subtracting the low frequencies from the original image. Then we took the low and high frequency images and added them to create our hybrid image.

Results in a table