function [status] = make_2d_images(number_of_images, image_width, image_height, position, width, height, width_variation, height_variation)
% MAKE_2D_IMAGES: Genrates examples of 2-D images and warps them in 1-D
%                 a scan-line at a time.
%
%    GENERAL
%
%      [status] = make_2d_images(n_images, image_width,
%         image_height, position, width, height, width_variation, height_variation)
%
%    INPUT/S
%
%      -number_of_images:
%           The number of images to generate.
%
%      -image_width:
%           The width of the 2-D images to be created.
%
%      -image_height:
%           The width of the 2-D images to be created.
%
%      -width:
%            The width of the object in the image.
%
%      -width_variation:
%            The width variation of the object in the image.
%
%      -position:
%            The horizontal position of the object in the image.
%
%      -height:
%            The height of the object in the image.
%
%      -height_variation:
%            The height variation of the object in the image.
%           
%    OUTPUT/S
%
%      -status
%           Status on the success of the process.
%
%    PENDING WORK
%
%
%    KNOWN BUG/S
%
%      -
%
%    COMMENT/S
%
%
%    RELATED FUNCTION/S
%
%      MAKE_1D_IMAGES, MAKE_1D_BUMP, REGISTER_2D_IMAGES
%
%    ABOUT
%
%      -Created:     January 6th, 2003
%      -Last update: January 6th, 2003
%      -Revision:    0.0.1
%      -Author:      R. S. Schestowitz, University of Manchester
% ==============================================================


warp_flag = 1;
          % should the images be warped (else only displayed)
verbose_mode = 1;
          % internally controlled parameter
debugging_mode = 1;
          % does extra tests

subplot_fig = figure;
H = figure(subplot_fig);

for i=1:number_of_images,
   if (verbose_mode == 1) 
     disp(['generating image #',num2str(i),' of ',num2str(number_of_images)]);
   end
   [index,current_image_vectors,current_point_vectors] = make_2d_bump(1, image_width, image_height, position, width, height, width_variation, height_variation);
   if (debugging_mode == 1) % view it if debugging
       size(current_image_vectors)
       index
   end 
   subplot(number_of_images+4,2,i);
   hold on;
   title(['Generated image #',num2str(i)]);   
   imshow(current_image_vectors);
   image_vectors(:,:,i) = current_image_vectors;
   point_vectors(:,:,i) = current_point_vectors;
   hold off;
end

if( warp_flag == 1),    
    number_of_iterations = 1;
         % how many iterations of the optimisation/warping to run
    
    reference_points_vector = point_vectors(:,:,1);
    reference_image_vector = image_vectors(:,:,1);
                % set reference to be the first image
    if (debugging_mode == 1) % view it if debugging
      subplot(number_of_images+4,2,number_of_images+2);
      hold on;
      title('Reference image');
      imshow(reference_image_vector);
      hold off;
    end 
         
    warped_images = image_vectors;
    warped_points = point_vectors;   % copy these values as warped variables are dynamic  
         
    for n=1:number_of_iterations,
                            % images are now warped one by one with respect to reference image
         for i=1:number_of_images,
                if (verbose_mode == 1) 
                   disp(['Warping image #',num2str(i),' of ',num2str(number_of_images)]);
                end
                current_image_vector_to_warp = warped_images(:,:,i);
                current_point_vector_to_warp = warped_points(:,:,i);
                
                % warp image using one objective function or another - currently msd_opt_together
                

                scores_mi(i) = mi(reference_image_vector, warped_images(:,:,i),10);
                scores_smsd(i) = sum(msd(reference_image_vector, warped_images(:,:,i)));
                             % get similarity measures
                subplot(number_of_images+4,2,number_of_images+3);        
                hold on;
                title('MI scores');
                plot(scores_mi,'*');
                hold off;   
                
                subplot(number_of_images+4,2,number_of_images+4);
                hold on;
                title('MSD scores'); 
                plot(scores_smsd,'*');
                hold off;
         end
         for current_scan_line=1:size(warped_images,1),
                % get scan lines of all images and a reference at a time
             current_lines = warped_images (current_scan_line,:,:)
             current_reference_line = reference_image_vector (current_scan_line,:)
             [images_post_registration(current_scan_line), points] = register_1d_images_set(
         end

                % create diagonal control points
                % send to 1-d registration function and save vectors on a new variable
                % append all vectors to form matrices
                % display matrices as images which are 1-d scanline warps
                % make this a pseudo NRR in 2-D which deals with scanlines in 1-D in practice
                % and generate gegistration videos or images 'pre-reg' and 'post-reg' to be put on public_html
                
%                 last_score = sum(msd(reference_image_vector, warped_images(:,:,2)))
%                 last_score = sum(msd(reference_image_vector, current_image_vector_to_warp))
%                 last_score = mi(reference_image_vector, warped_images(:,:,2),10)
%                 last_score = mi(reference_image_vector, current_image_vector_to_warp,10)              
%                 
%                 [grid, steps] = setup_grid(2, unwarped_image, ref_points, placement_method, n_points);
%                 
%                 
%                 
%                 warp_params.green = 'biharmCPS';
%                 param_list = [];
%                 start_image = current_image_vector_to_warp;
%                 start_points = current_point_vector_to_warp;
%                 
%                 
%                 warped_grid = grid;
%                 last_score = eval_msd_multi_warp(zeros(size(grid)),grid, unwarped_image, unwarped_points, ref_image, ref_points, 20, warp_params);
%                 [params, score] = fminsearch(@eval_msd_multi_warp,zeros(size(grid)),optimset('Display',verbose,'TolX',1e-10),grid, unwarped_image, unwarped_points, ref_image, ref_points, 20, warp_params);
%                 param_list(size(param_list,1)+1,:).d = params;
%                 warped_grid = grid + params;
%                 start_points = nrr_trans_1d(start_points, grid, warped_grid, warp_params,[]);
%                 start_image = interp1(unwarped_points,unwarped_image,start_points, 'linear',0);
%                 disp(['Initial score: ',num2str(last_score),' Final score: ',num2str(score)]);
%                 warped_points = start_points;
%                 warped_image = start_image;         
    end    
end    


status = 0;
     % report okay status