function H = homography(x0, x1)
  if ~all(size(x1)==size(x0))
    error('Data sets x1 and x0 must have the same dimension');
  end
    
  [rows,npts] = size(x1);
  if rows~=2 & rows~=3
    error('x1 and x2 must have 2 or 3 rows');
  end
  A = [];

  z = zeros(1,3);
  for i= 1:size(x1,2)
    A = [ A; -x1(:,i)', z, x0(1,i)*x1(:,i)'];
    A = [ A; z, -x1(:,i)', x0(2,i)*x1(:,i)'];

  end

  [~,~,V] = svd(A,0);
  H = V(:,end);
  H = reshape(H,[3,3])';