Project 1: Image Filtering and Hybrid Images

For Project 1, students were to apply the principles of filtering to create a MATLAB function that filters any given image with filters of any size with odd row and column pixels. To test if the filter function is implemented properly, a given image was debugged with identity filter, box filter, Gaussian filter, oriented filter, and high pass filter (Laplacian and else) respectively. The second portion of the project was to develop a hybrid image by combining two images (one that is low pass filtered and the other that is high pass filtered) such that the image looks like one upclose and like the other from a distance.

Filtering function

The filter function that I wrote first measures the size of the image and that of the filter. Then, it creates a dummy image of zeros with the size of the origial image plus the size the of filter minus the center row and column. Then, the original image is mirrored onto the dummy variable at the center. Then, in the loop, the filter is applied to the new image variable, but at the borders (of the original image), the dummy pixels that are outside the boundaries of the original image are applied to the filters. The new pixel after the filtering operation is then designated to the output image.

Code for my_imfilter.m


function output = my_imfilter(image, filter)
[r, c, t] = size(image);
[fr, fc] = size(filter);
im = zeros(r+fr-1,c+fc-1, t);
im((fr+1)/2:(fr+1)/2+r-1,(fc+1)/2:(fc+1)/2+c-1, :) = image;
for i = 1:r
    for j = 1:c
        output(i,j,1) = sum(sum(im(i:i+fr-1,j:j+fc-1,1).*filter));
        output(i,j,2) = sum(sum(im(i:i+fr-1,j:j+fc-1,2).*filter));
        output(i,j,3) = sum(sum(im(i:i+fr-1,j:j+fc-1,3).*filter));
    end
end
end


Results of filtering

Hybrid Images

In order to generate a hybrid image, Gaussian filter applied using varying standard deviation to generated a low-pass image of one using Gaussian blurring, and a high-pass image of the other by subtracting the blurred image by using filtering from the original image. Then a hybrid image is formed when the two resulting images are added together. For reference, the standard deviation (in pixels) was chosen as 9.

Results

Image to apply high-pass filter

Image to apply low-pass filter

high frequency image

low frequency image

Hybrid Image

Intermidiate Images

Here are examples of a few more hybrid images: