CS 143 / Project 1 / Image Filtering and Hybrid Images

Final Results

The code of my divides into two parts.

  1. my_imfilter
  2. my_conv2

The code is as follows.

my_conv2

The following code is for my_conv2. It makes convolution of the filter and image.


function output = my_conv2(Image, filter)
  k = size(filter, 1);
  Image1 = padarray(Image,[(k-1)/2,(k-1)/2]);
  s = size(Image1);
  Image2 = zeros(s(1),s(2));

  for i = 1+(k-1)/2: s(1)-(k-1)/2
      for j =1+ (k-1)/2: s(2)-(k-1)/2
	  temp = Image1(i-(k-1)/2:i+(k-1)/2,j-(k-1)/2:j+(k-1)/2) .* filter;
	  Image2(i,j)= sum(temp(:));
      end
  end
  output = Image2;
end

my_imfilter

The following code is for my_imfilter. It divides image to 3 color chanels and then process them individually.

function output = my_imfilter(image, filter)
  redImage = image(:,:,1);
  greenImage = image(:,:,2);
  blueImage = image(:,:,3);

  redOutput = my_conv2(redImage, filter);
  greenOutput = my_conv2(greenImage, filter);
  blueOutput = my_conv2(blueImage, filter);
  output =cat(3,redOutput,greenOutput, blueOutput);
end  

Results in a table

original dog low_frequencies dog hybrid_image
original cat high_frequencies cat