function [returned_images, returned_points] = register_1d_images_set(reference_image, reference_points, images, images_points, number_of_iterations)
% REGISTER_1D_IMAGES_SET: registers a set of images according to
%                         a given reference image
%
%
%    GENERAL
%
%      build_1d_bump_model(spline_type, placement_type, objective_function)
%
%    INPUT/S
%
%      -reference_image:
%           Reference image for registration.
%
%      -reference_points:
%           The points that describe the warps applied to the reference image.
%
%      -images:
%           The images to be registered
%
%      -images_points:
%           The points that describe the warps applied to the images.
%
%      -number_of_iterations:
%           The number of iterations corresponding to warps.
%           
%    OUTPUT/S
%
%      -returned_images:
%           The images passed in post-warping. These exclude the reference image
%           which is, of course, unchanged.
%
%      -returned_points:
%           The points that describe the warps applied to the images
%
%    PENDING WORK
%
%
%    KNOWN BUG/S
%
%
%    COMMENT/S
%
%          7/1/04: Need to get points of reference image and images to be passed on to objective functions
%          called only from MAKE_2D_IMAGES and was never used successfully
%          as early 2-D efforts had been aborted.
%          
%    RELATED FUNCTION/S
%
%      MAKE_2D_IMAGES
%
%    ABOUT
%
%      -Created:     January 7th, 2004
%      -Last update: January 7th, 2004
%      -Revision:    0.0.1
%      -Author:      R. S. Schestowitz, University of Manchester
% ==============================================================
      
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% variables (parameters) initialisation

         % spline type 'single_point' or 'multi_point'
spline_type = 'multi_point';
         % placement type for multipoint: 'grid' or 'edges' or 'random'
         % placement type for singlepoint: 'overlap_grid' or 'edges_and_scale' or 'random_and_scale'
placement_type = 'edge';
objective_function = 'msd_opt_together';
verbose = 'off';
         % be verbose or not
n_points = 5;
         % an argument that is passed to the model optimisation function.
         % meaning still unknown.

ref_shift = 0.2;
       % shift in reference image??
max_shift = 0.2;
       % maximum allowed shift?
step = 0.1;
       % used below only
spec_iters = 25;
       % specificity iterations
gen_iters = 25;
       % generalisability iterations
min_error = 0;
max_error = 1;
       % define error range??
error_step = 0.1;
n_error_steps = (max_error-min_error)/error_step;

for n=1:number_of_iterations
  disp(['Itereation number ',num2str(n)]);
       % Smith: correct registration
       % attempt to register
  for i=1:size(images(2)),
     disp(['Warping image ',num2str(i),' of ',num2str(size(images(2))]); 
     
     image_vec = warped_images(:,i);
     points_vec = warped_points(:,i);

     if(strcmp(objective_function,'model_opt_together'))
             [param_list, warped_point, warped_image, score] = optimise_all_warps_model([warped_images(:,1:i-1),warped_images(:,i+1:n_images)], [warped_points(:,1:i-1),warped_points(:,i+1:n_images)], image_vec, points_vec,spline_type,placement_type,n_points, 0, 0);
     elseif(strcmp(objective_function,'model_opt_separate'))
             [param_list, warped_point, warped_image, score] = optimise_warps_model([warped_images(:,1:i-1),warped_images(:,i+1:n_images)], [warped_points(:,1:i-1),warped_points(:,i+1:n_images)], image_vec, points_vec,spline_type,placement_type,n_points, 0, 0);
     elseif(strcmp(objective_function,'msd_opt_together'))
             [param_list, warped_point, warped_image, score] = optimise_all_warps_msd(reference_image, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, 0, 0);
     elseif(strcmp(objective_function,'msd_opt_separate'))
             [param_list, warped_point, warped_image, score] = optimise_warps_msd(reference_image, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, 0, 0);
     else
         error(['Unknown objective function: ', objective_function]);
     end

     warped_images(:,i) = warped_image;
     warped_points(:,i) = warped_point;

  end  % end:images
end  % end:iterations

returned_images = warped_images
returned_points = warped_points