CS 143 / Project 1 / Image Filtering and Hybrid Images

Example of me and Sara.

I like the given filter, and I want to learn more, so I create my own filter which is really cool! You can set up the shape to be whatever you like as long as its width and length are odd numbers.

  1. Self-made filter.
  2. Width and Length of the filter can be changed by the user each time.
  3. The distribution of value of the filter can be displayed, very cool!

I evaluated the value of each parameters in the filter matrix by using the multivariate normal distribution, in this project, I made distribution of value like a Gaussian. The values closer to the center of the filter are larger than those farther, which means each pixel is infected by its neighbors, and the closer the neighbor is, the larger impact it has. I also tried another way to write the filter, which is to give the value of each pixel by the distance between its location and the center of the filter, and then get the sum of all the values of pixels, then multiply each value by (1/sum(value of pixel)). This method is also good, however, it makes the MATLAB run really slow, so I prefer the multivariate normal distribution method. .

Example heading

These photos are the examples.

Example of code with highlighting

The javascript in the highlighting folder is configured to do syntax highlighting in code blocks such as the one below.


%example code
function [F,X1,X2] = my_imfilter(user_r,user_c)
if(nargin ~= 2)
error(['please type in correct number of arguments'])
end
disp(['The number of rows of the filter is ' num2str(user_r)]);
disp(['The number of the colums of the filter is ' num2str(user_c)]);
mu = [0, 0];
Sigma = [3 0; 0 3];
x1 = ((1 - user_r) / 2 ):((user_r - 1) / 2);
x2 = ((1 - user_c) / 2 ):((user_c - 1) / 2);
[X1,X2] = meshgrid(x1,x2);
F = mvnpdf([X1(:) X2(:)],mu,Sigma);
F = reshape(F, length(x2),length(x1));
temp_sum = sum(sum(F));
F=F/temp_sum;
figure
surf(x1,x2,F);
caxis([min(F(:))-.5*range(F(:)),max(F(:))]);
axis([((1 - user_r) / 2 ) ((user_r - 1) / 2) ((1 - user_c) / 2 ) ((user_c - 1) / 2) 0 .7])
xlabel('x1'); ylabel('x2'); zlabel('Filter Distribution');

Results in a table

I had a lot of fun doing this assignment, Computer Vision is more interesting than I thought.Thanks Professor James!