Project 1: Image Filtering and Hybrid Images

Example of a Hybrid Image.

Hybrid images are static images generated from two different images which give two different views based on the distance from where the user is viewing the image. The project deals with using the concept of image filtering to generate hybrid images. The key components about the project are:

  1. Image Filtering.
  2. Low frequency Components of image.
  3. High frequency Components of image.

Hybrid image exploits the concept of low frequency and high frequency component of images. Low and high frequency components can be extracted from their respective images using different filtering techniques. The combination of these two images results in hybrid image. The low frequency image component is visible when hybrid image is viewed from a far distance, whereas high frequency component of image is visible when hybrid image is viewed from short distance.

The implementation of project

The project implementation has been done in Matlab. The filter that we have used for the filtering purposes is 'Guassian Filter'. The low frequency component of the image is calculated by convoluting the original image with the guassian filter. The controlling parameter here is the cut-off frequency which controls the size of the filter and the standard deviation parameter of the filter. Similarly the high component of second image is calculated by computing the low frequencies for the second image and subtracting this from the original image. The combination of two images results in hybrid image. The main implemenation of the project was that of filtering process, the code snippet of which can be found below.

Implementation of the function

The matlab code in the my_imfilter.m is implemented as follows.


%example code
[image_rows, image_cols, img_channels] = size(image);
[filter_rows, filter_cols] = size(filter);
if( mod(filter_rows,2)==0 || mod(filter_rows,2)==0)
    disp('Filter cannot have even number of rows/columns')
    output = zeros(image_rows, image_cols);
    output = im2single(output);
else
for rows=1:1:image_rows+(filter_rows-1)
    for cols = 1:1:image_cols+(filter_cols-1)
        for ch = 1:1:img_channels
            if(rows<=(filter_rows-1)/2 || cols<=(filter_cols-1)/2 || rows > (image_rows+(filter_rows-1)/2) || 
									cols> (image_cols+(filter_cols-1)/2) ) 
                img2(rows,cols,ch) = im2single(255);
            else
                img2(rows,cols,ch) = image(rows-(filter_rows-1)/2,cols-(filter_cols-1)/2,ch);
            end
        end
    end
end

for rows=1:1:image_rows
    for cols=1:1:image_cols
        for ch = 1:1:img_channels
            sum=0;
            for k =1:1:filter_rows
                for l =1:1:filter_cols
                   sum = sum + img2(rows+k-1,cols+l-1,ch)*filter(k,l);
                end
            end
            output(rows,cols,ch)=sum;
        end
    end
end

Results in a table

The images above show the results of the algorithm implemented algorithm. As can be seen hybrid images of different qualities are generated depending on the estimation of cut-off frequency. The tweaking of cut-off frequency for appropriate generation of hybrid generation involves knowledge of frequency domain and can be found out using trial and error method. Various different pair of images which are similar in size and have similar orientation of object in observation can be used for generation of hybrid images.