%COMP 256 Assignment 2
%Adrian Ilie

function [r1,r2]=rectify(f,pointfile)
%computes the two homographies for rectification (as in Hartley)

%compute the location of the epipoles
[e1,e2]=epipoles(f);

%load point data
[p1,p2,num]=loadpointdata(pointfile);

%compute homographies for each point correspondence
h1=zeros(3,3,num);
h2=zeros(3,3,num);
for i=1:num
  h1(:,:,i)=homography(f,e1,p1(:,i));
  h2(:,:,i)=homography(f,e2,p2(:,i));
end

%average the results
r1=mean(h1,3);
r2=mean(h2,3);