Project 1: Image Filtering and Hybrid Images

Image Filtering

The first step in this project was replicating MatLab's built in imfilter() function to get a better understanding of how image filtering works. The main part of the code for this function focused on convoluting all the channels of a color image separately with a filter.


paddedImage = padarray(image, [xPad,yPad]);
if (z == 3)
    for p = 1:3
        for i = xPad+1:n+xPad
            for j = yPad+1:m+yPad
                dotProduct = paddedImage(i-xPad:i+xPad, j-yPad:j+yPad, p) .* filter;
                filteredImage(i-xPad,j-yPad, p) = sum(dotProduct(:));
            end
        end
    end
else

This code checks to see if the image is a color image, and if so, it performs the convolution of the filter and the zero padded image and stores the result in the appropriate pixel of the result image. This code uses xPad and yPad (the X and Y offset of the center pixel in the filter) to find the appropriate pixel in the final image to store the result of the convolution, and therefore, works with any size image and any odd size filter.

In the table below, the image you see to the right is filtered through several filters of varying length and produces the outputs in the table beneath.

Filter Results

Hybrid Images

Next I created some hybrid images using the my_imfilter() function that I created, to apply a Gaussian blur to the images in order to remove the low frequencies from one image and the high frequencies from the other. Then, the hybrid image can be created by combining the two images.


filter = fspecial('Gaussian', cutoff_frequency*4+1, cutoff_frequency);

low_frequencies = my_imfilter(image1, filter);
high_frequencies =  image2 - my_imfilter(image2, filter);

hybrid_image = low_frequencies + high_frequencies;

Using the two images above and the process outlined in the previous paragraph, I separated the low_frequencies in the Marilyn picture and the high frequencies in the Einstein picture and combined them to create the hybrid image seen below those using a cutoff frequency of 8.

More Hybrid Images