Project 1: Image Filtering and Hybrid Images

Hybird image of a cat and a dog.

In this project, I have wrote my image filtering function and have used it to create hybrid images. Hybrid images are generated by superimposing two images at two different spatial scales. High frequencies dominate the near view perception but only the low frequency part of the image can be seen from distance.

Filter Function

    My filter's implementation imitates the default behaviour of imfilter() in matlab. Following are the features supported:

  1. Supports any kind of filter but only with odd dimentions.
  2. Deals with boundary issues with zero padding on both the sides.
  3. Supports rgb and grayscale image type.

Result of testing filter function

From left to right, then top to bottom: Original, identity, blur, large blur, sobel, high pass, laplacian

Implementation


% code for filter function
n_dim = ndims(image);
img_sz = size(image);
half_pad_sz = floor(size(filter)/2);
pad_sz_i = 2* half_pad_sz(1);
pad_sz_j = 2* half_pad_sz(2);
padded_img = padarray(image,half_pad_sz);
output = zeros(img_sz);

if n_dim == 1
    for i = 1:img_sz(1)
       for j = 1:img_sz(2)
           output(i,j) = sum(dot( padded_img(i:i+pad_sz_i, j:j+pad_sz_j), filter));
       end
    end    
else
    for ch = 1:n_dim
        for i = 1:img_sz(1)
           for j = 1:img_sz(2)
               output(i,j,ch) = sum(dot( padded_img(i:i+pad_sz_i, j:j+pad_sz_j, ch), filter));
           end
        end
    end    
end


Hybrid Images

Hybrid images are generated by superimposing two images at two different spatial scales. High frequencies dominate the near view perception but only the low frequency part of the image can be seen from distance. There is a constraint to this that the images should be aligned good enough for the effect.

Experiment results

cutoff_frequency1 is the cut off for low pass filter.
cutoff_frequency2 is the cut off for high pass filter(used in the (image - image*filter) manner).

cutoff_frequency1 = 9;
cutoff_frequency2 = 5;
From left to right: low frequency image, high frequency image, hybrid image, hybrid image at different scales

cutoff_frequency1 = 4;
cutoff_frequency2 = 2;
From left to right: low frequency image, high frequency image, hybrid image, hybrid image at different scales

cutoff_frequency1 = 9;
cutoff_frequency2 = 3;
From left to right: low frequency image, high frequency image, hybrid image, hybrid image at different scales

cutoff_frequency1 = 4;
cutoff_frequency2 = 8;
From left to right: low frequency image, high frequency image, hybrid image, hybrid image at different scales

cutoff_frequency1 = 10;
cutoff_frequency2 = 2;
From left to right: low frequency image, high frequency image, hybrid image, hybrid image at different scales

For extra credits

Here I have experimented with changing orientation in the picture as well as the face when viewing from far and near the image. Can be used for viewing pics in a workplace where the information is not supposed to be shared with other divisons.


cutoff_frequency1 = 5;
cutoff_frequency2 = 3;
From left to right: low frequency image, high frequency image, hybrid image, hybrid image at different scales

Here I have experimented with different frames of a video to create a time lapse effect. When we move from far to near the image it will look like the player is swinging the bat and will give a video kind of effect. Although this is very raw, because it has only two frames, but I would try in future for hybrid images with more than 3 image.


cutoff_frequency1 = 7;
cutoff_frequency2 = 5;
From left to right: low frequency image, high frequency image, hybrid image, hybrid image at different scales