function points = perturb_points(points, variance)
% PERTURB_POINTS: Perturbs the points in an image.
%
% Code written by Katherine Smith, 2003
%
%    GENERAL
%
%      points = perturb_points(points, variance)
%
%    INPUT/S
%
%      -points:
%           The points in their original (initial) position.
%
%      -variance:
%           The variance allowed for perturbation.
%           
%    OUTPUT/S
%
%      -points:
%           The points after they have been perturbed.
%
%    PENDING WORK
%
%      -
%
%    KNOWN BUG/S
%
%      -None.
%
%    COMMENT/S
%
%      -
%
%    RELATED FUNCTION/S
%
%      
%
%    ABOUT
%
%      -Created:     November 23rd, 2003
%      -Last update: Novermber 26th, 2003
%      -Revision:    0.0.2
%      -Author:      R. S. Schestowitz, University of Manchester
% ==============================================================

perturbation = zeros(size(points)); 
                  % initialise all to 0, i.e. 0 change
                  % Smith: don't warp the first or the last
perturbation(2:size(points)-1,:) = randn(size(points,1)-2,1) * variance; 
                  % pertub w.r.t. variance. It defines the weight of the possible
                  % random permutations.
points = points + perturbation; 
                  % apply perturbation to points by simple summation
                  % Smith: resort in case any of the points have crossed over each other
points = sort(points);
                  % Note: there is a function that checks of points have crossed over
                  % elsewhere in Kate's code.
points = normalise_to_bounds(points, 1,size(points,1));
                  % normalise in case any have gone out of bounds (I think below 0 and above 1)