Project 1: Image Filtering and Hybrid Images

Example of a hybrid image.

This project requires student to implement an image filtering function and replicating some of the work in a paper regarding hybrid images. My work includes the following parts:

  1. Image filtering with mirror padding which supports grayscale images and RGB images.
  2. Hybrid image generator.
  3. Conducting experiment using two cutoff frequencies.

For the first part, identity filter, box filter, Gaussian filter, Oriented filter, high pass filter are used for both intensity and color pictures. In the remaining part, as suggested by the paper, I choose two different cutoff frequencies to obtain a better hybrid image.

Part1: Image filtering with mirror padding

Image and filter can both be represented as matrices, and filtering is nothing more than doing matrix multiplication for every pixel. One thing that should be noted is how to apply filter on the boundaries of the input image. There are multiple available approaches, and the one I use here is mirror padding. The padded values are the reflection of edges in the input image. RGB image filtering is an extention of the grayscale image filtering as we only need to apply filter on each of its channels.

Code for image filtering with mirror padding


% Get dimension of image and filter.
[m,n] = size(image);
[a,b] = size(filter);

% padding size
x_plus = (b-1)/2;
y_plus = (a-1)/2;
% mirror padding among x-axis
im_padded = [flip(image(:,1:x_plus),2), image, flip(image(:,n-x_plus+1:n),2)];
% mirror padding among y-axis
im_padded = [flip(im_padded(1:y_plus,:),1); im_padded; flip(im_padded(m-y_plus+1:m,:),1)];

% filtering
out = zeros(m, n);
for x=1:n
    for y=1:m 
      new_x = x_plus+x;
      new_y = y_plus+y;
      % the square used to calculate the filtered value.
      s = im_padded(new_y-y_plus:new_y+y_plus, new_x-x_plus:new_x+x_plus); 
      value=sum(sum(s.*filter));
      out(y,x)=value;
    end
end

Results of image filtering with mirror padding

Filters appled from left to right are indentity filter, small box blur filter, Gaussian blur filter, oriented filter, Discrete Laplacian high pass filter, and Gaussian high pass filter.

Part2: Hybrid image

A hybrid image is shown above, and it is a combination of low frequency information of a dog and high frequency information of a cat. In my implementation, low frequency information is obtained by using my image filter mentioned above, while the high frequency information is obtained by substracting low frequency information from the image.

Code for hybrid image


filter = fspecial('Gaussian', cutoff_frequency*4+1, cutoff_frequency);

low_frequencies = my_imfilter(image1, filter);

high_frequencies = image2-my_imfilter(image2, filter);

hybrid_image = low_frequencies + high_frequencies;

Results of hybrid image

From left to right are the low frequency information of a dog, the high frequency information of a cat, the hybrid image and the hybrid image with various scales. The last picture clearly illustrates two kind of species when viewed from different distances. Viewed from a close distance, it appears like a cat because human eyes focus more on high frequency information so that low frequency information about the cat is skipped. While viewed from far distance, high frequency data decreases significantly as distance increases so that low frequency part is perceived by our eyes and therefore a dog appears.

Part3: Hybrid image using two cutoff frequencies

In part 2, I use the same cutoff frequency for the two images. In this part, I try to use two different ones, and the value is chosen empirically.

Code for hybrid image with two cutoff frequencies


% parameters are chosen empirically.
cutoff_frequency1 = 6;
cutoff_frequency2 = 4;
filter1 = fspecial('Gaussian', cutoff_frequency1*4+1, cutoff_frequency1);
filter2 = fspecial('Gaussian', cutoff_frequency2*4+1, cutoff_frequency2);

low_frequencies = my_imfilter(image1, filter1);

high_frequencies = image2-my_imfilter(image2, filter2);

hybrid_image = low_frequencies + high_frequencies;


Results of hybrid image

This is all I have accomplished so far. Feel free to contact me at yliu858@gatehc.edu if you have further problems.