function F = goldstandardcost(x)
%This function is an input to lsqnonlin in panoramaGS.m
%the last nine columns of the 2*n+9 element x are expected to
%to be the homography H-hat.  all the x's then all the y's.
global INITIAL_X
s = size(x);
n = s(1)-9;
X = [x(1:n/2)'; x((n/2+1):n)'];  %%MAYBE I SHOULD SWAP...
X(3,:) = ones(1,n/2);
H = [x((n+1):(n+3))'; x((n+4):(n+6))'; x((n+7):(n+9))'];
%H is the current homography.
PreImerr = (INITIAL_X - X);
PostImerr1 = H*INITIAL_X;
PostImerr1(1,:) = PostImerr1(1,:)./PostImerr1(3,:);
PostImerr1(2,:) = PostImerr1(2,:)./PostImerr1(3,:);
PostImerr = H*X;
PostImerr(1,:) = PostImerr(1,:)./PostImerr(3,:);
PostImerr(2,:) = PostImerr(2,:)./PostImerr(3,:);
PostImerr = PostImerr1 - PostImerr;

%Should I make the coordinates inhomogeneous? Yes, so
%that the error functional can be 4n.
PreImerr(1,:) = PreImerr(1,:);%./PreImerr(3,:);
PreImerr(2,:) = PreImerr(2,:);%./PreImerr(3,:);

F = [PreImerr(1,:) PostImerr(1,:) PreImerr(2,:) PostImerr(2,:)]';


