function points = perturb_points_cps(points, error)
% PERTURB_POINTS_CPS: Perturbs the points in an image using Clamped-Plate
%                     Spline warps.
%
% Code written by Katherine Smith, 2003
%
%    GENERAL
%
%      points = perturb_points_cps(points, error)
%
%    INPUT/S
%
%      -points:
%           The points in their original (initial) position.
%
%      -error:
%           Controls the perturbation weight.
%           
%    OUTPUT/S
%
%      -points:
%           The points after they have been perturbed.
%
%    PENDING WORK
%
%      -
%
%    KNOWN BUG/S
%
%      -None.
%
%    COMMENT/S
%
%      -Performs several warps so might be slow.
%
%    RELATED FUNCTION/S
%
%      
%
%    ABOUT
%
%      -Created:     November 23rd, 2003
%      -Last update: Novermber 26th, 2003
%      -Revision:    0.0.2
%      -Author:      R. S. Schestowitz, University of Manchester
% ==============================================================

% slap some random warps down
% don't warp the first or the last

n_warps = 5; 
             % number of warps??
interval = (max(points)-min(points))/n_warps;
             % interval is the margin between maxima and minima divided
             % by the number of warps??
max_shift = error * 0.67 * (interval/2);
             % maximum shift is guided by error value multiplied
             % by mysterious numbers
for i = 0:n_warps-1;
             % for all warps (0-4 inclusive)
  warp_centre = min(points) + i*interval + interval/2;
             % set some centre
  shift = rand * max_shift;
  shift = shift/(interval/2-1);
             % should say: (rand * max_shift)/(interval/2-1);
             % What does that mean in practice?
  points = cps_warp_1d(points, warp_centre, interval/2-1, shift);
            % apply a clamped-plate spline warp
end