function score = eval_mi_cps_warp(params, warp_centre, r, start_points_vec, start_image_vec, ref_image_vec)
% EVAL_MI_CPS_WARP: get similarity score between CPS warped image and
%                    reference. (Evaluate the clamped-plate spline warp using
%                    mean-squared-difference)
%
% Code written by Katherine Smith, 2003
%
%    GENERAL
%
%      score = eval_msd_cps_warp(params, start_points_vec, ref_image_vec)
%
%    INPUT/S
%
%      -params:
%           The paramters of the warps.
%
%           params(1): warp centre
%           params(2): r
%           params(3): d
%
%      -warp centre:
%           Not in parameters already??
%
%      -r:
%           Not in parameters already??
%
%      -start_points_vec:
%           Points before CPS warp.
%
%      -start_image_vec:
%           Image before CPS warp.
%
%      -ref_image_vec:
%           The reference image to be compared to.
%           
%    OUTPUT/S
%
%      -score:
%           The similarity score w.r.t. the reference image. 
%           (Mutual information)
%
%    PENDING WORK
%
%      -
%
%    KNOWN BUG/S
%
%      -None.
%
%    COMMENT/S
%
%      -
%
%    RELATED FUNCTION/S
%
%      LINEAR_WARP, MSD, EVAL_MSD, 
%      EVAL_MODEL_MULTI_WARP
%
%    ABOUT
%
%      -Created:     November 23rd, 2003
%      -Last update: Novermber 27th, 2003
%      -Revision:    0.0.4
%      -Author:      R. S. Schestowitz, University of Manchester
% ==============================================================

% warp_centre = params(1);
% r = params(1);
d = params(1);

% rescale

% normalise params to 1

max_d = 0.67;

%scaled_d = d/r;

if ((abs(d) > max_d) | ((warp_centre-r <0) | (warp_centre+r > max(start_points_vec))))

     % if any of the parameters is not between -0.67 
     %and 0.67, or the warp's location or size is invalid
  score = size(start_points_vec,1); % set to number of points???
else 
     % if okay
  warped_points = cps_warp_1d(start_points_vec,warp_centre,r,d); 
     % apply warp
  warped_image = interp1(start_points_vec,start_image_vec,warped_points, 'linear',0);
     % interpolate to create warped image from the warped points
  score = mi(ref_image_vec, warped_image, 256); 
     % score acc to mutual information measure (entropy)
end
params 
     % display parameters and score (still under debugging??)
score