CS 143 / Project 1 / Image Filtering and Hybrid Images

Example of hybrid image

The goal of this assignment is to write an image filtering function and use it to create hybrid images using a simplified version of the SIGGRAPH 2006 paper by Oliva, Torralba, and Schyns. Hybrid images are static images that change in interpretation as a function of the viewing distance. The basic idea is that high frequency tends to dominate perception when it is available, but, at a distance, only the low frequency (smooth) part of the signal can be seen. By blending the high frequency portion of one image with the low-frequency portion of another, you get a hybrid image that leads to different interpretations at different distances. The funcion my_imfilter(image,filter) was implemented to this task. The funcion have 2 inputs:

  1. image: a matrix that represents an image
  2. filter: a matrix that represents a filter (a gaussian filter, in this case).

Padding

The funcion padarray() was used to pad the image synmetrically, as we can se in the code below.

padarray()


for j=1:zpixels
    image2(:,:,j) = image(:,:,j)';
end
image2 = padarray(image2,n-1,'symmetric');
for j=1:zpixels
    imageWork(:,:,j) = image2(:,:,j)';
end
imageWork = padarray(imageWork,n-1,'symmetric');
image = imageWork;

Filtering

The core of the funcion my_imfilter(); function is the code below..

filtering


for k=1:m(3)
    for i=n:(m(1)-(n-1))
        for j=n:(m(2)-(n-1))
            new_image(i-(n-1),j-(n-1),k) = 0;
            for z=1:((2*n)-1)
                for h=1:((2*n)-1)
                    new_image(i-(n-1),j-(n-1),k) = new_image(i-(n-1),j-(n-1),k)+(filter(z,h)*double(image(i-n+z,j-n+h,k)));
                end
            end       
        end
    end
end

Results in a table

More Results of the filter and more hybrid images