%% Compare Lane Boundary Models
% Create a set of ground truth points, add noise to simulate actual lane boundary points, and compare the simulated data to the model.
% Create a set of points representing ground truth by using parabolic parameters.

parabolaParams1 = [-0.001 0.01 0.5];
parabolaParams2 = [0.001 0.02 0.52];
x = (0:0.1:20)';
y1 = polyval(parabolaParams1,x);
y2 = polyval(parabolaParams1,x);

%
% Add noise relative to the offset parameter.

y1 = y1 + 0.10*parabolaParams1(3)*(rand(length(y1),1)-0.5);
y2 = y2 + 0.10*parabolaParams2(3)*(rand(length(y2),1)-0.5);

%
% Create a set of test boundary models.

testlbs = parabolicLaneBoundary([-0.002 0.01 0.5;
                                 -0.001 0.02 0.45;
                                 -0.001 0.01 0.5;
                                  0.000 0.02 0.52;
                                 -0.001 0.01 0.51]);

%
% Compare the boundary models to the ground truth points. Calculate the precision and sensitivity of the models based on the number of matches, misses, and false positives.

threshold = 0.1;
[numMatches,numMisses,numFalsePositives,~] = ...
        evaluateLaneBoundaries(testlbs,{[x y1],[x y2]},threshold);

disp('Precision:');
disp(numMatches/(numMatches+numFalsePositives));
disp('Sensitivity/Recall:');
disp(numMatches/(numMatches+numMisses));

% Copyright 2012 The MathWorks, Inc.