Project 1: Image Filtering and Hybrid Images

A fish or a sub?

For this project I first created my own implementation of image filtering that mimics the functionality of matlab's imfilter function. Then I used my_imfilter to create hybrid images in accordance with Oliva, Torralba, and Schyns 2006 paper: Hybrid images.

Part 1: my_imfilter:

The filtering algorithm used here is quite straightforward. Given an IxJ image and an MxN filter it does the following. For every pixel in the image, my_imfilter does pairwise multiplication between each of the MxN filter pixels and the corresponding MxN pixels surrounding the current pixel. The resulting scalar is then placed in an IxJ output image. (Note that in the implementation all 3 color channels are taken care of at once, so this partial result is really a 3x1 vector and not a scalar).


%my_imfilter core loop

for i = 1:image_dimensions(1); % width of image pre-padding
    for j = 1:image_dimensions(2); % height of image pre-padding
        
        % matrix operations are used here to do the pairwise multiplications all at once 
        % for the MxN pixels around the central pixel and for all 3 color channels
        subsection = image(i:i+size(filter,1)-1, j:j+size(filter,2)-1, : );
        output(i, j, :) = sum(sum(subsection.*dimensionalfilter, 1), 2);

    end
end

Edge cases are handled by adding padding around the input image. The padding used here is a mirror image of the edge of the original image, because this leads to good filtering results for most images and filters.

Part 2: Hybrid images:

The next part of the project was to create hybrid images. For this step I put five sets of two images through some filters and then combined the results to create the results below. For each of the five sets, I took both images and blurred them. Then I output the first image without any additional modifications - these are the low frequencies. The second image, however, required more work. To isolate the high frequencies I subtracted the blurred version of the second image from the original second image. Of course, this left me with an image with an average pixel intensity of zero, so I added .5 to normalize the pixel intesities. This results in an image of the high frequencies.

The final step of creating a hybrid image was to average these two resulting images (the low frequency version of image 1 and the high frequency version of image 2), leading to the results seen below.