CS 143 / Project 1 / Image Filtering and Hybrid Images

Figure 1 : Example of a Hybrid Image from this project.

Overview

Hybrid Image is an image that can be interpret differently, depend on the viewing distance. The idea behind it is to combine images in low and high frequency together. Figure 1 is the example of using this process on cat and dog pictures, with low frequency from dog image and high frequency from cat image.

The goal of this project is to implement a working Hybrid Image generator, and also our own Image Filtering along the ways. However, the result images can varies greatly depend on the pair of images used and the cut off frequency chosen for the filter. Some results are very convincing, but some are not so.

Algorithm

  1. Image Filtering
  2. The algorithm for filtering an image in this project is to do a convolution between image and the filter. The convolution process can be written as the following:

    
    for c = 1:size(image,3) % to support color image, the value will be 1 for gray image
    
        for i = 1:size(image,2) 
    	for j = 1:size(image,1)  % for each pixel
    		neighbor = image_padded(i:i+size(filter,1)-1,j:j+size(filter,2)-1,c); % pick filter size region of image
    		output(i,j,c) = sum(sum(neighbor.*filter)); % sum over the result
    	end
        end
    end
    
    

    Note that the image used in this algorithm have to be padded before entering for loop. The padding process is necessary to ensure that the result will be of the same size as the input image. The following matlab code show the example of padding by adding zero or the reflection of image to the border.

    
    % offset
    x = (size(filter,2)-1)/2;
    y = (size(filter,1)-1)/2;
    
    % zero
    image_padded = padarray(image,[y x],0,'both');
    % mirror
    image_padded = padarray(image,[y x],'replicate','both');
    
    

    Figure 3 : Example of adding zero to the border of image.

    Figure 2 : Example of adding reflection to the border of image.

  3. Hybrid Images
  4. In order to produce Hybrid Images, 2 different images in low/high frequency will be combined together. Figure 4-5 show cat and dog picture that had been combined into Figure 1.

    Figure 5 : High frequency image of cat.

    Figure 4 : Low frequency image of dog.

    To create high/low frequency images, one simply filter them with the appropriate filter.

    By combining them together, the result will be a hybrid image that, depend on viewing distant, can be interpret as both pictures.

Results

Using the algorithm describe above, the following images are the some convincing results I got. Image 1 corresponding to image that will be used as a low frequency, while Image 2 is for use as high frequency. Note that swapping their position gives out different result.

Image 1Image 2 Result

Conclusion

It may be pretty simple to combine 2 image together, and get Hybrid Image. However, to get a convincing image, the 2 image used must have some similarity to begin with. Out of all the results, I think cat/dog and Einstein/Marilyn pairs are most convincing as Hybrid Images. In both case, 2 image are almost at the same position, with each component (ie, eyes, nose, mouth) at around the same place. I found that color are also matter in making the result believable. To put it simply, we get blurred shading information, including color, from the low frequency image, and the high frequencies become mostly the outline of image. The outline from high frequency image will disappear if we look at it from far far away but can be seen pretty clear when look closely. Since looking up close we see both shading and outlining, the trick is to make this close up image looks pretty believable. If the shading from one image align well with the line from another image, we then get a very convincing result.

Figure 6 : Low frequency image of cat.

Figure 7 : High frequency image of baby.