CS 143 / Project 1 / Image Filtering and Hybrid Images

Hybrid images are created by combining the high frequencies from one image with the low frequencies of another.

Creating the my_imfilter method

First we need to create a filter method that applies a filter to an image. To do so for a given image 'g' and filter 'f' to create a new image 'r', each pixel i, j of r will be the sum of all numbers in an f sized subarray of g centered on i, j and padded with zeroes if necessary multiplied by f. For images with multiple colors, each color channel is filtered independently. The code representation of this is as follows:


s = size(image);
f = size(filter);
r = zeros(s);
for k = 1:s(3)
    for i = 1:s(1)
        for j = 1:s(2)
            subim = image(max(i-floor(f(1)/2),1):min(i+f(1)-floor(f(1)/2)-1,s(1)),
            				max(j-floor(f(2)/2),1):min(j+f(2)-floor(f(2)/2)-1,s(2)), k);
            subim = padarray(subim, [max(1-(i-floor(f(1)/2)), 0)], 'pre');
            subim = padarray(subim, [max((i-floor(f(1)/2)+f(1)-1)-s(1), 0)], 'post');
            subim = padarray(subim, [0, max(1-(j-floor(f(2)/2)), 0)], 'pre');
            subim = padarray(subim, [0, max((j-floor(f(2)/2)+f(2)-1)-s(2), 0)], 'post');
            temp = subim .* filter;
            r(i,j,k) = sum(temp(:));
        end
    end
end

Creating the hybrid images

To create the hybrid image, apply a filter to an image to filter out the high frequencies (effectively blurring the picture). Take a second picture and filter out the low frequencies (take out the high frequencies and subtract the low frequency picture form the original image). Then combine the images together by making the value of each pixel the sum of the two processed pictures

Some examples