function [F] = reestimateF(inl, func)
%Joshua Stough
%COMP 290-89, Pollefeys
%Assignment 2, Computing F
%This function uses lsqnonlin on the F matrix
%and the inlier correspondences from previous 
%step to find the best F for those inliers.

global inliers X XP

inliers = inl;

%build X and XP

s = size(inliers);
X = inliers(1:2,:);
X(3,:) = ones(1,s(2));

XP = inliers(3:4,:);
XP(3,:) = ones(1,s(2));

%this is a 4n+9 optimization problem.  But I'm
%not doing that.  I want the best F for the
%inlier points provided.

F = computeF_8point(inliers);
%The initial F.

x0 = reshape(F,1,9);

%options = optimset('MaxIter', 20);
x = lsqnonlin(func, x0, -1000, 1000);

%Fold = F;
F = reshape(x,3,3);

%Print out, for fun, the ratio of the two matrices.
%F./Fold


