CS 143 / Project 1 / Image Filtering and Hybrid Images

Dog-Cat Hybrid Images.

Hybrid Images is a technology that combines low-spatial frequencies of one picture with the high spatial frequencies of another picture. By using this method, an image with an interpretation changes with viewing distance is produced.

Example heading

This project is about how to write an image filtering function and use it to create hybrid images. There are two parts are inlcuded.The first part is Image Filtering. we need to write a function to implement the basic function of built in function imfilter().The other part is to implement the function to generate the Hybrid Images, which is the sum of a low-pass filtered version of the one image and a high-pass filtered version of a second image.

Example of code with highlighting

One of the most important part of this project is the my_imfilter function. Since the matrix of picture is in 3D, I used 3 for-loop to travel through all the points. Assume the matrix is [x,y,z], I use the most outside loop to take all the value for z, then try to read a 2D image matrix[x,y] and pad it based on the size of filter matrix. For each point, use filter to caclulate its new value, and give it to output.

%example code
for level=1:n
    nimage=image(:,:,level)
    newimage=padarray(nimage,[padrow,padcol],'symmetric');
   
    [row,col]=size(newimage);

        for i=padrow+1:row-padrow
            for j=padcol+1:col-padcol
                matrix=newimage(i-padrow:i+padrow,j-padcol:j+padcol) .* filter;
                output(i-padrow,j-padcol,level)=sum(matrix(:));
            end
        end
end



Results in a table

filter test result

Hybrid Images

The project works well, no bugs were found so far.If trying more value for fliter, the result may be more accurate