Project 1: Image Filtering and Hybrid Images

In this project we worked on creating an algorithm to filter images. We used this algorithm to take the put one image through a low pass filter and another image through a high pass filter and then combined the two images to form one hybrid image much like the one to the right. Below is the code I used to filter images.


function output = my_imfilter(image, filter)
    convulsion = rot90(rot90(filter));
    padding = floor(size(filter) ./ 2);

    heightbound = padding(1);
    widthbound = padding(2);

    padded = padarray(image, padding);
    [height width depth] = size(padded);

    result = zeros(size(image));

    for i=(1 + heightbound):1:(height - heightbound)
        for j=(1 + widthbound):1:(width - widthbound)
            for k=1:1:depth
                point = sum(dot(padded(i - heightbound:i + heightbound, j - widthbound:j + widthbound, k),
                        convulsion));
                result(i - heightbound,j - widthbound, k) = point;
            end
        end
    end
    output = result;
end

my_imfilter

Looking at the algorithm, it is relatively simple. It first rotates the filter 180 degrees. It then pads the image with zeros so the resulting image will be the same size. Finally, it iterates over every pixel for ever color channel and calculates the resulting output pixel by taking teh dot product between the padded image pixeles and the filter centered at that pixel. The output will be the filtered image.

Hybrid Images

Once the filtering function is in place, we can now create hybrid images. Hybrid images are created from two images.

You then take the low pass filter of one image...

and the high pass of the other image

And then add the results to get...

More Hybrid Images