Home > Source > Bin > build_1d_bump_model_1.m

build_1d_bump_model_1

PURPOSE ^

==============================================================

SYNOPSIS ^

function [status] = build_1d_bump_model(spline_type, placement_type, objective_function,apply_intensity_offset, save_movie, do_plot, movie_type,progress_bar, user_menu, produce_statistics,see_model_before_each_iteration, show_pixels, show_score_vs_iteration,show_model_after_optimisation, show_specificity_statistics, verbose_score,movie_name, window, average_smooth_enabled, gaussian_smooth_enabled,bump_width, bump_width_variation, bump_height, bump_height_variation,bump_position_freedom, initial_diminish_factor, smoothness_factor,plot_before_and_after, number_of_bins, model_evaluation_method,show_score_using_model, handle, n_modes, shape_weight,weighting_normalisation_method, variation_kept,run_all_objective_functions, kernel, save_data, load_data,save_bumps, draw_warp_curve, overlap_scores, show_target,format, filter, filter_level, model_score_type, gen_iters,spec_iters, draw_curve_by_images);

DESCRIPTION ^

 ==============================================================
 BUILD_1D_BUMP_MODEL: Builds a 1-D model for some bump data
                      and returns some related statistics.

 Code originally written by Katherine Smith, 2003

    GENERAL

      Omitted.

    INPUT/S

      -- No arguments will lead to defaults

      -spline_type: 
           The type of spline to be used. 'single_point' or
           'multi_point' at present.

      -placement_type:
           Placement type for 'multi_point':
                    'grid' or 'edges' or 'random'
           placement type for 'single_point':
                    'overlap_grid' or 'edges_and_scale'
                    or 'random_and_scale'.

      -objective_function:
           'msd_opt_together' or 'model_opt_separare' or
           'msd_opt_separate' or 'model_opt_together'.

      .....
           
    OUTPUT/S

      -status:
           The status of the operation of this routine (to be returned at
           the end

      -Figures produced and results displayed are main
       data to be utilised.

    PENDING WORK

      -

    KNOWN BUG/S

      -

    COMMENT/S

      -Different video outputs are generated but controlling which
       one is chosen is not trivial. It currently just does the
       job of experimentation and showing results as pixels
       or bumps.

    RELATED FUNCTION/S

      See other functions in same directory, filenames
      beginning with "build" in particular. There seem to be much
      overlap due to cut-and-paste.

    ABOUT

      -Created:     December 29rd, 2003
      -Last update: February 18th, 2004
      -Revision:    0.6.6
      -Author:      R. S. Schestowitz, University of Manchester
 ==============================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [status] = build_1d_bump_model( ...
0002     spline_type, placement_type, objective_function, ...
0003     apply_intensity_offset, save_movie, do_plot, movie_type, ...
0004     progress_bar, user_menu, produce_statistics, ...
0005     see_model_before_each_iteration, show_pixels, show_score_vs_iteration, ...
0006     show_model_after_optimisation, show_specificity_statistics, verbose_score, ...
0007     movie_name, window, average_smooth_enabled, gaussian_smooth_enabled, ...
0008     bump_width, bump_width_variation, bump_height, bump_height_variation, ...
0009     bump_position_freedom, initial_diminish_factor, smoothness_factor, ...
0010     plot_before_and_after, number_of_bins, model_evaluation_method, ...
0011     show_score_using_model, handle, n_modes, shape_weight, ...
0012     weighting_normalisation_method, variation_kept, ...
0013     run_all_objective_functions, kernel, save_data, load_data, ...
0014     save_bumps, draw_warp_curve, overlap_scores, show_target, ...
0015     format, filter, filter_level, model_score_type, gen_iters, ...
0016     spec_iters, draw_curve_by_images);
0017 
0018 % ==============================================================
0019 % BUILD_1D_BUMP_MODEL: Builds a 1-D model for some bump data
0020 %                      and returns some related statistics.
0021 %
0022 % Code originally written by Katherine Smith, 2003
0023 %
0024 %    GENERAL
0025 %
0026 %      Omitted.
0027 %
0028 %    INPUT/S
0029 %
0030 %      -- No arguments will lead to defaults
0031 %
0032 %      -spline_type:
0033 %           The type of spline to be used. 'single_point' or
0034 %           'multi_point' at present.
0035 %
0036 %      -placement_type:
0037 %           Placement type for 'multi_point':
0038 %                    'grid' or 'edges' or 'random'
0039 %           placement type for 'single_point':
0040 %                    'overlap_grid' or 'edges_and_scale'
0041 %                    or 'random_and_scale'.
0042 %
0043 %      -objective_function:
0044 %           'msd_opt_together' or 'model_opt_separare' or
0045 %           'msd_opt_separate' or 'model_opt_together'.
0046 %
0047 %      .....
0048 %
0049 %    OUTPUT/S
0050 %
0051 %      -status:
0052 %           The status of the operation of this routine (to be returned at
0053 %           the end
0054 %
0055 %      -Figures produced and results displayed are main
0056 %       data to be utilised.
0057 %
0058 %    PENDING WORK
0059 %
0060 %      -
0061 %
0062 %    KNOWN BUG/S
0063 %
0064 %      -
0065 %
0066 %    COMMENT/S
0067 %
0068 %      -Different video outputs are generated but controlling which
0069 %       one is chosen is not trivial. It currently just does the
0070 %       job of experimentation and showing results as pixels
0071 %       or bumps.
0072 %
0073 %    RELATED FUNCTION/S
0074 %
0075 %      See other functions in same directory, filenames
0076 %      beginning with "build" in particular. There seem to be much
0077 %      overlap due to cut-and-paste.
0078 %
0079 %    ABOUT
0080 %
0081 %      -Created:     December 29rd, 2003
0082 %      -Last update: February 18th, 2004
0083 %      -Revision:    0.6.6
0084 %      -Author:      R. S. Schestowitz, University of Manchester
0085 % ==============================================================
0086       
0087 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0088 %% variables (parameters) initialisation           %%
0089   
0090 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0091 %% Input Defaults              %%
0092 
0093 if (nargin == 0),
0094     disp(' ');
0095     disp('Argument(s) ommited. Using defaults instead.');
0096     disp(' ');
0097     spline_type = 'multi_point';
0098          % SMITH: spline type 'single_point' or 'multi_point'
0099          % SMITH: placement type for multipoint: 'grid' or 'edges' or 'random'
0100          % SMITH: placement type for singlepoint: 'overlap_grid' or 'edges_and_scal or 'random_and_scale'
0101     placement_type = 'random';
0102          % controls knotpoint selection on the grid
0103     objective_function = 'model_opt_together';
0104          % choice of objective function
0105     apply_intensity_offset = 1;
0106          % 0: Offset should not be applied to data
0107          % 1: Offset enabled
0108     
0109     save_movie = 0;
0110          % should movie be saved (boolean)
0111          % 0: No
0112          % 1: Yes
0113     do_plot = 0;
0114          % should bumps be plotted as it changes? (Boolean)
0115          % (Old comment: this also enables frames being captured which slows down the
0116          % process. Capturing of frames and plotting can potentially be separated to make
0117          % this routine more useful).
0118     movie_type = 1;
0119          % type of movie to save
0120          % 0: bumps as pixels. do_plot may be 0 for a pixel clip to be recorded.
0121          % 1: bump plots. Remember to set do_plot to 1.
0122     movie_name = 'undefined';
0123     format = 'png';
0124     gen_iters = 25;
0125        % generalisability iterations = 25;
0126        % specificity iterations
0127     spec_iters = 25;
0128        % specificity iterations
0129     progress_bar = 1;
0130          % display progress bar or text instead
0131          % 0: Hierarchical Text
0132          % 1: Progress bar
0133          % 2: Quiet
0134          % 3: Console progress bar
0135     model_score_tyype = 'Deafault';
0136     user_menu = 0;
0137     number_of_bins=50;
0138          % 0: parameters need to be set in file
0139          % 1: menu input
0140     produce_statistics = 0;
0141          % should statistics be displayed at the end (boolean)
0142     see_model_before_each_iteration = 0;
0143          % should a combined model be produced and displayed before each
0144          % iteration, this should be set to 1
0145     show_pixels = 0;
0146          % show pixels representation (boolean). Mandatory for pixel movie
0147          % capture
0148     show_score_vs_iteration = 0;
0149     show_model_after_optimisation = 0;
0150     show_specificity_statistics = 0;
0151          % more booleans which are self-explanatory
0152     verbose_score = 0;
0153          % boolean: display score or not after optimisation
0154     average_smooth_enabled = 0;
0155     gaussian_smooth_enabled = 0;
0156     window = 1;
0157     
0158     plot_before_and_after = 0;
0159          % will only ever be used if the two above are set
0160     bump_width = 0.2;
0161     bump_width_variation = 0.5;
0162     bump_height = 0.2;
0163     bump_height_variation = 0.3;
0164     bump_position_freedom = 0.9;
0165     initial_diminish_factor = 2;
0166     smoothness_factor = 17;
0167          % set the bump parameters
0168 
0169     model_evaluation_method = 1;
0170                       % 1: Determinant
0171                       % 0: MDL
0172                       % 2: Sum of log of Eigenvalues
0173     show_score_using_model = 0;
0174     handle = 'Default';
0175       % give figures a fefault name
0176     n_modes = 20;
0177     variation_kept = 0.99;
0178       % keep 99%
0179       % number of modes in the model to be accounted for
0180     shape_weight = 0.06;  
0181     weighting_normalisation_method = 'edge';
0182     run_all_objective_functions = 0;
0183        % do not try running all the objective functions
0184     called_from_gui = 0;
0185        % indicate that GUI was not used in this case
0186     kernel = 'Exponential';
0187     save_data = 0;
0188     load_data = 0;
0189     save_bumps = 0;
0190     draw_warp_curve = 0;
0191     draw_curve_by_images = 0;
0192     overlap_scores = 0;
0193     show_target = 0;
0194         % do not show perfectly aligned images estimate
0195 else
0196     called_from_gui = 1;
0197         % indicate that default values were not set and that the function
0198         % was called from REGISTER
0199 end
0200 
0201 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0202 %% Optimisation Controllers    %%
0203 
0204 % The values below will be defaults if user menu does not appear
0205 
0206 n_images = 2;
0207          % how many images to try to register in each set
0208 n_iterations = 2;
0209          % how many iterations of the optimisation to run, default was 50.
0210 n_sets = 1;
0211          % how many sets of images to register (in order to get better statistics)
0212 image_width = 50;
0213          % the number of pixels or the lenght of the data vector
0214 n_points = 5;
0215          % an argument that is passed to the model optimisation function.
0216          % meaning still unknown.
0217 
0218        
0219 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0220 %% Input / Output              %%
0221 
0222 warning off;
0223          % keeps st_pca.m quiet
0224 error_found = 0;
0225          % status flag
0226 status = ['                      '];
0227          % set intiaial status packet
0228 if (run_all_objective_functions == 1),
0229     colour = 'r';
0230         % set initial colour for overlaid plots
0231     style = ':';
0232         % similarly to style of line
0233     progress_bar = 2;
0234 end
0235      % the progress indicators will not work for this routine so disable
0236      % them
0237 
0238 
0239 verbose = 'off';
0240          % be verbose or not during general-purpose optimisation
0241 if strcmp(movie_name, 'undefined'),
0242     movie_name = ['movie_', spline_type, '_', placement_type, '_', objective_function,'_width', num2str(image_width), '_images', num2str(n_images), '_iterations', num2str(n_iterations), '.avi'];
0243          % name for the AVI to be saved
0244          % The name will attempt to encompass all construction details
0245 end
0246          
0247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0248 %% Others (most are obsolete)  %%
0249                        
0250 % white_ctr = 0;
0251          % white counter? Was used for simple bumps in code that is now
0252          % commented out
0253 % ref_shift = 0.2;
0254        % shift in reference image??
0255 % max_shift = 0.2;
0256        % maximum allowed shift?
0257 % step = 0.1;
0258        % used in two lines below only
0259 % los = zeros(n_images,floor((max_shift-ref_shift)/step));
0260 % his = zeros(n_images,floor((max_shift-ref_shift)/step));
0261        % not understood yet
0262 % blurred = 0;
0263        % image blurring has been applied to images (boolean)
0264 % min_error = 0;
0265 % max_error = 1;
0266        % define error range??
0267 % error_step = 0.1;
0268 % n_error_steps = (max_error-min_error) / error_step;
0269 
0270 frame_counter = 0;
0271          % counter for video frames. Do not fiddle with this variable.
0272 
0273 if (progress_bar == 0),
0274  progress_indicator_type = 'Hierarchical Text';
0275 elseif (progress_bar == 1),
0276  progress_indicator_type = 'Progress Bar';
0277 elseif (progress_bar == 2),
0278  progress_indicator_type = 'Quiet'; 
0279 elseif (progress_bar == 3),
0280  progress_indicator_type = 'Console Progress Bar';
0281 else
0282  error('Callback value for progress indicator is not recognised');
0283 end
0284 
0285          % do type conversions for input to make code below readable
0286          
0287 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0288 %% Begin Set initialisation    %%
0289 
0290 if (user_menu == 1),
0291   [n_sets, n_iterations, n_images, image_width] = get_parameters_from_user('Default');
0292 end 
0293 
0294 tic;
0295        % start counting time
0296 for this_set = 1:n_sets
0297        % for all sets
0298        % Old: user gets status about set number. Multiple sets generate reliable
0299        %      statistics
0300   tic;
0301        % This is called again (stack of time counters????? Doesn't seem so)
0302        % This will need to be changed (one tic omitted) for the statistics
0303        % to work properly. Only one stopwatch can work at a time.
0304        % Smith: for each set of n_sets images, build a model
0305        % calculate obj fn values from these models, plot the mean with error
0306        % bars given by 1 stddev away
0307   if (strcmp(progress_indicator_type,'Hierarchical Text')),      
0308     disp(['calculating set ', num2str(this_set), ' out of ', num2str(n_sets), ' sets...']);
0309   elseif (strcmp(progress_indicator_type,'Progress Bar')),
0310       gui_active(1);     % will add an abort button
0311       if (strcmp(getenv('OS'), 'Linux')),
0312          h = progressbar( [], 0, 'Preparing for registration', [['Registration Progress on '], [get_host]]);
0313       else
0314          h = progressbar( [], 0, 'Preparing for registration', 'Registration Progress');
0315       end
0316   end    
0317 
0318   
0319   if (strcmp(progress_indicator_type,'Progress Bar')),
0320            h = progressbar( h, 0, 'Fetching Data');
0321   end
0322           
0323 
0324   if (load_data == 0),
0325       [imagelist, images, points] = make_1d_bump(n_images, image_width...
0326           , bump_width, bump_width_variation, bump_height, bump_height_variation...
0327           , bump_position_freedom, initial_diminish_factor, smoothness_factor...
0328           , save_bumps, format);
0329        % create a set of images
0330       if (called_from_gui == 1 & save_bumps == 1),
0331         status = [[status];['(**) Images saved     '];['                      ']];
0332       end
0333   else
0334       output = open([[handle],['.mat']]);
0335       points = output.points;
0336       images = output.images;
0337                   % copy the data structures from the file
0338   end     
0339   
0340   if (save_data == 1)
0341       save([[handle],['.mat']], 'images','points');
0342       if (called_from_gui == 1),
0343         status = [[status];['(**) Data saved       '];['                      ']];
0344       end
0345   end
0346   
0347   figure;
0348   [X,Y] = meshgrid(n_images, -image_width/2:1:image_width/2-1);
0349   Z = zeros(n_images, image_width);
0350 size(X)
0351 size(Y)
0352 size(Z)
0353 size(images)
0354   for i = 1:n_images,
0355     Z(:,i) = images(:,i);
0356   end  
0357   mesh(X,Y,Z);
0358   axis([-30 30 -30 30 -1 1]);
0359   % plot3(1:2,1:2,images(1,:))
0360   
0361   
0362   if (strcmp(progress_indicator_type,'Progress Bar')),
0363            h = progressbar( h, 0, 'Pre-processing Data');
0364   end
0365   
0366   if (average_smooth_enabled),
0367       images = average_smooth(images, window);
0368   end  
0369   
0370   if (gaussian_smooth_enabled),
0371          images = gaussian_smooth(images, window); 
0372   end
0373        % smooth all images - used to be disabled and set <blurred> to 1
0374        
0375   if (apply_intensity_offset),
0376       vertical_pane_location = 3;
0377                        % Need is for only 3 columns in plot
0378   else
0379       vertical_pane_location = 2;
0380                        % Need is for only 2 columns in plot
0381   end
0382 
0383   points = -1 + 2 * (points - 1) / (image_width - 1);
0384        % Smith: normalise points from -1 to 1
0385        %% keep = 0.999999; NOTE (RSS Feb. 2004): became obsolete
0386        % Is this precision required? Perhaps in optimisation.
0387   ref_points_vec = points(:,1);
0388   ref_image_vec = images(:,1);
0389        % set first image generated to be reference
0390   % ref_hi = his(1);
0391   % ref_lo = los(1);
0392        % and get its upper and lower boundaries. his and lois were
0393        % generated and returned as output for simple bumps
0394 
0395        
0396   if (draw_warp_curve == 1),
0397        overlap_curve_fig = figure('Name','Overlapping Warp Curves');
0398   end
0399   
0400   if (show_pixels == 1),
0401     pixels_figure = figure('Name','Pixel Representation');
0402   end
0403   
0404   
0405   
0406   if (draw_curve_by_images == 1),
0407     curve_subplot_fig = figure('Name',[['Warp Curves for all data - objective function: '],[objective_function]]);
0408     curves = figure(curve_subplot_fig);
0409     for i=1:n_images,
0410        subplot(n_images, n_iterations + 1, i * (n_iterations + 1) - n_iterations);
0411        hold on;
0412        axis off;
0413        plot(points(:,i));
0414        axis([-1 image_width -1 1]);
0415        hold off;
0416     end
0417   end
0418   
0419 
0420 %%             END OF INITIALISATION               %%
0421 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0422 
0423 
0424 
0425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0426 %% Warping images, then modelling warped images    %%
0427 %% attempt to register images by warping.          %%
0428   if (plot_before_and_after),
0429     for i=1:n_images,
0430        images_before_offset(:,i) = images(:,i);
0431     end
0432   end
0433   if (do_plot),
0434     subplot_fig = figure('Name',[[handle],[': Left: Original images ; Right: Images subjected to warping']]);
0435     H=figure(subplot_fig);
0436     for i=1:n_images,
0437        subplot(n_images, vertical_pane_location, (vertical_pane_location * i) - vertical_pane_location + 1);
0438        hold on;
0439        plot(images(:,i));
0440        % title(['Unwarped image #',num2str(i)]);
0441        axis([0 image_width 0 1]);
0442        grid on;
0443        hold off;
0444     end
0445   else
0446     subplot_fig = 0;
0447       % pass a void figure to the optimisation functions
0448   end
0449   
0450   if (apply_intensity_offset),
0451       for index = 1:n_images,
0452          peak (index) = max(images(:,index));
0453       end
0454       peak_reference = max (peak);  
0455       for index = 1:n_images,
0456         peak_difference = peak_reference - max(images(:,index));
0457         images(:,index) = images(:,index) + peak_difference;
0458         if (do_plot),
0459             subplot(n_images, vertical_pane_location, (vertical_pane_location * index) - vertical_pane_location + 2);
0460             hold on;
0461             plot(images(:,index));
0462             % title(['Unwarped image #',num2str(i)]);
0463             axis([0 image_width 0 1]);
0464             grid on;
0465             hold off;
0466         end
0467       end        
0468   end 
0469 %% NOTE: Change here in traversal above (RSS, December 2003)
0470   
0471     still_to_go = 1;
0472           % condition for while loop. This will enable the program to
0473           % continually try all objective functions.
0474     
0475     
0476     while (still_to_go == 1),
0477     
0478     if (run_all_objective_functions == 0)
0479         still_to_go = 0;
0480            % break out of while loop after just one iteration
0481     else
0482            % try all objective functions sequentially
0483        if strcmp(objective_function, 'all'),
0484            % meaning that it is in its first iteration
0485            objective_function = 'model_opt_together';
0486        elseif strcmp(objective_function, 'model_opt_together'),
0487            objective_function = 'model_opt_separate';    
0488        elseif strcmp(objective_function, 'model_opt_separate'),
0489            objective_function = 'msd_opt_together';
0490        elseif strcmp(objective_function, 'msd_opt_together'),
0491            objective_function = 'msd_opt_separate';
0492        elseif strcmp(objective_function, 'msd_opt_separate'),
0493            objective_function = 'mi_opt_together';
0494        elseif strcmp(objective_function, 'mi_opt_together'),
0495            objective_function = 'mi_opt_separate';
0496        elseif strcmp(objective_function, 'mi_opt_separate'),
0497            objective_function = 'nmi_opt_together';
0498        elseif strcmp(objective_function, 'nmi_opt_together'),
0499            objective_function = 'nmi_opt_separate';
0500        elseif strcmp(objective_function, 'nmi_opt_separate'),           
0501            objective_function = 'void';   
0502            still_to_go = 0;
0503               % signal to break out of the while loop because the test of
0504               % all objective functions is finished.
0505        else
0506            error('Problem with <Run All Objective Functions> option');
0507        end
0508     end   
0509     
0510       warped_images = images;
0511       warped_points = points;
0512           % set this initial state to plot the examples before change
0513     
0514     
0515     % correctly_warped_points = points;
0516     % correctly_warped_images = images;
0517     % for i=1:n_images
0518     % % now bung in the right deformations to get them back
0519     % correctly_warped_points(:,i) = linear_warp(ref_points_vec, los(i,white_ctr), his(i,white_ctr), ref_lo, ref_hi);
0520     % correctly_warped_points_vec = correctly_warped_points(:,i);
0521     % image_vec = images(:,i);
0522     % % resample at the warped points - point on reg. grid has value of point at same index in warpy grid
0523     % % need to interpolate
0524     % correctly_warped_images(:,i) = interp1(ref_points_vec, image_vec, correctly_warped_points_vec);
0525     % correct_model = build_model(correctly_warped_images,correctly_warped_points,1,'','edge',0);
0526     % converging_score(i) = measure_model(correct_model.variances,50);
0527     % end
0528     % figure,plot(log(converging_score)),title('Log of score as model converges');
0529     
0530       if ((strcmp(progress_indicator_type,'Console Progress Bar')) | (strcmp(progress_indicator_type,'Progress Bar')))
0531          progress_bar_position = 0;
0532          time_for_this_iteration = 10;
0533          total_images = n_images * n_iterations;
0534          step_size = 50 / total_images;
0535       end   
0536         % initialise progress bar
0537       for n = 1:n_iterations,
0538         if (strcmp(progress_indicator_type,'Hierarchical Text'))  
0539            % iterations aim to get good statistical results by averaging
0540           disp(['    +-Running iteration number ',num2str(n), ' out of ',num2str(n_iterations), ' iterations...']);
0541         end     
0542         
0543            % Smith: correct registration
0544            % attempt to register
0545            
0546         if (see_model_before_each_iteration),  
0547           w_c_model = build_model(warped_images, warped_points, variation_kept,'Optimised warp', weighting_normalisation_method);
0548                   % create an appearance model...
0549           show_combined_model(w_c_model,ref_points_vec, 2, 2, [[handle],[': Combined model before iteration number ', num2str(n)]]);
0550                   % and show the model before each iteration
0551         end          
0552         for i = 1:n_images,
0553            % start iteration time counter
0554          if (strcmp(progress_indicator_type,'Hierarchical Text')),
0555            disp(['        +-Warping image ',num2str(i),' out of ',num2str(n_images), ' images in total...']);
0556          end
0557          
0558          this_step = ((n-1) * n_images) + i;
0559                     
0560          if (strcmp(progress_indicator_type,'Progress Bar')),
0561            tic;
0562            progress_bar_position = progress_bar_position + step_size;
0563            steps_remaining = (n_images * n_iterations) - this_step;
0564            minutes = floor(time_for_this_iteration * steps_remaining / 60);
0565            seconds = rem(floor(time_for_this_iteration *  steps_remaining), 60);
0566            max_count   = 50;
0567                % The console-based GUI is 50 units wide
0568            if (seconds > 9),
0569                h = progressbar( h, step_size/50,['            Estimated remaining time: ', num2str(minutes), ':', num2str(seconds)]);
0570            else
0571                h = progressbar( h, step_size/50,['            Estimated remaining time: ', num2str(minutes), ':0', num2str(seconds)]);
0572            end    
0573            if ~gui_active,
0574                     error_found = 1;
0575                     break; % if aborted was pressed
0576            end
0577               % use the third-part GUI-like progress bar (added February
0578               % 2004)
0579          end
0580          if (strcmp(progress_indicator_type,'Console Progress Bar')),
0581                                % if console progress bar
0582            tic;
0583            progress_bar_position = progress_bar_position + step_size;
0584            clc;
0585            disp(['|=================================================|']);
0586            progress_string='|';       
0587            for counter = 1:floor(progress_bar_position),
0588                progress_string = [progress_string, '#'];
0589            end
0590            disp(progress_string);
0591            disp(['|================= ',num2str(floor(progress_bar_position * 2)),'% completed =================|']);
0592                           % display progress per cent
0593            steps_remaining = (n_images * n_iterations) - this_step;
0594            minutes = floor(time_for_this_iteration * steps_remaining / 60);
0595            seconds = rem(floor(time_for_this_iteration *  steps_remaining), 60);
0596            disp(' ');
0597            if (seconds > 9),
0598              disp(['            Estimated remaining time: ', num2str(minutes), ':', num2str(seconds)]);
0599                           % show time indicators
0600            else
0601              disp(['            Estimated remaining time: ', num2str(minutes), ':0', num2str(seconds)]);
0602            end
0603          end
0604          image_vec = warped_images(:,i);
0605          points_vec = warped_points(:,i);     
0606          
0607          if (show_pixels == 1),   
0608              appended_vector=[];
0609              for current_image=1:n_images,
0610                appended_vector=[[appended_vector],[warped_images(:,current_image),[warped_images(:,current_image)]],[warped_images(:,current_image)]];
0611                    % append bump data 3 times for width which is visible
0612              end
0613            
0614                  %% appended_vector=appended_vector * 256
0615                  %% use if scale of 0..255 used
0616     
0617              G = figure(pixels_figure);
0618              hold on;
0619               % title('Bumps as pixels');
0620              imshow(appended_vector',[0,1]);
0621                        % show as an image
0622              if (movie_type == 0 & save_movie == 1),
0623                   frame_counter = frame_counter + 1;
0624                   M(frame_counter) = getframe(G);
0625              end
0626              hold off;
0627          end
0628                   
0629          if (movie_type == 1 & save_movie == 1 & do_plot == 1),
0630                    frame_counter = frame_counter + 1;
0631                    M(frame_counter) = getframe(H);
0632          end
0633                    % capture pixels frame
0634          if    (strcmp(objective_function,'model_opt_together')),
0635                  [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, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, model_evaluation_method, n_modes, weighting_normalisation_method, shape_weight, variation_kept);
0636          elseif(strcmp(objective_function,'void')),        
0637                  break;
0638          elseif(strcmp(objective_function,'model_opt_separate')),
0639                  [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, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, model_evaluation_method, n_modes, weighting_normalisation_method, shape_weight, variation_kept);
0640          elseif(strcmp(objective_function,'msd_opt_together')),          
0641                  [param_list, warped_point, warped_image, score] = optimise_all_warps_msd(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score);
0642          elseif(strcmp(objective_function,'msd_opt_separate')),
0643                  [param_list, warped_point, warped_image, score] = optimise_warps_msd(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score);
0644          elseif(strcmp(objective_function,'mi_opt_together')),         
0645                  [param_list, warped_point, warped_image, score] = optimise_all_warps_mi(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, number_of_bins);
0646          elseif(strcmp(objective_function,'mi_opt_separate')),
0647                  [param_list, warped_point, warped_image, score] = optimise_warps_mi(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, number_of_bins);
0648          elseif(strcmp(objective_function,'nmi_opt_together')),         
0649                  [param_list, warped_point, warped_image, score] = optimise_all_warps_nmi(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, number_of_bins);
0650          elseif(strcmp(objective_function,'nmi_opt_separate')),
0651                  [param_list, warped_point, warped_image, score] = optimise_warps_nmi(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, number_of_bins);
0652          elseif(strcmp(objective_function,'mixed_msd_model')),
0653                     if (((n / n_iterations < 2 / 10) & (n / n_iterations >= 1 / 10)) |...
0654                         ((n / n_iterations < 4 / 10) & (n / n_iterations >= 3 / 10)) |...
0655                         ((n / n_iterations < 6 / 10) & (n / n_iterations >= 5 / 10)) |...
0656                         ((n / n_iterations < 8 / 10) & (n / n_iterations >= 7 / 10)) |...
0657                         ((n / n_iterations < 10 / 10) & (n / n_iterations >= 9 / 10))),
0658                       [param_list, warped_point, warped_image, score] = optimise_all_warps_msd(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score);
0659                     else
0660                       [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, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, model_evaluation_method, n_modes, weighting_normalisation_method, shape_weight, variation_kept);
0661                     end                    
0662          elseif(strcmp(objective_function,'model_post_msd')),
0663                     if (n / n_iterations < 1 / 2),
0664                         % for the first half
0665                       [param_list, warped_point, warped_image, score] = optimise_all_warps_msd(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score);
0666                     else
0667                         % and for the second half
0668                       [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, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, model_evaluation_method, n_modes, weighting_normalisation_method, shape_weight, variation_kept);
0669                     end
0670          elseif(strcmp(objective_function,'tfc_eccv')), 
0671                  % msgbox('TFC ECCV 2004: Under Construction.');
0672                  pdf_evalution_method = 'Default';
0673                  [param_list, warped_point, warped_image, score] = optimise_groupwise([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, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, model_evaluation_method, n_modes, weighting_normalisation_method, shape_weight, variation_kept, pdf_evalution_method, kernel);         
0674          elseif(strcmp(objective_function,'wavelet_complexity')),  
0675                  % msgbox('Wavelets: Under Construction.');
0676                  wavelet_evalution_method = 'Default';
0677                  [param_list, warped_point, warped_image, score] = optimise_wavelet([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, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, model_evaluation_method, n_modes, weighting_normalisation_method, shape_weight, variation_kept, wavelet_evalution_method, filter, filter_level);         
0678          
0679          else
0680                  error(['Unknown objective function: ', objective_function]);
0681          end
0682          
0683          if (draw_warp_curve == 1),
0684            figure(overlap_curve_fig);
0685            hold on;
0686            plot(warped_points);   
0687            hold off;
0688          end  
0689          
0690          if (draw_curve_by_images == 1),
0691              figure(curves);
0692              subplot(n_images, n_iterations + 1, i * (n_iterations + 1) - (n_iterations - n));
0693              hold on;
0694              axis off;
0695              plot(warped_points(:,i));
0696              axis([-1 image_width -1 1]);
0697              hold off;
0698          end 
0699          
0700          warped_images(:,i) = warped_image;
0701          warped_points(:,i) = warped_point;
0702     
0703          % figure(subplot_fig),title(['Warped images, after image ',num2str(i),' iteration ',num2str(n)]);
0704          % dummy = waitforbuttonpress;
0705          
0706          if (show_score_using_model == 1),           
0707              % if evaluation is through model then always overwrite score
0708             c_model = build_model(warped_images, warped_points, variation_kept, '', weighting_normalisation_method, shape_weight);
0709                 % first build a model
0710             if (strcmp(model_score_type, 'Default')),
0711                 score = measure_model(c_model.variances, n_modes, model_evaluation_method, c_model);
0712             elseif (strcmp(model_score_type, 'Specificity')),  
0713                 score = find_specificity(c_model, images, spec_iters, ref_points_vec);
0714             elseif (strcmp(model_score_type, 'Generalisability')),  
0715                 score = find_generalisability(c_model, gen_iters);
0716             elseif (strcmp(model_score_type, 'Mean MSD')),
0717                 score = measure_model_msd(warped_images);
0718             elseif (strcmp(model_score_type, 'All')),
0719               % score = measure_model(c_model.variances, n_modes, model_evaluation_method, c_model);
0720                             % use deafult as score that is primary
0721                 all_scores = [[find_specificity(c_model, images, spec_iters, ref_points_vec)], [find_generalisability(c_model, gen_iters)], [measure_model_msd(warped_images)]];    
0722                            % get all scores above and store them in a
0723                            % matrix
0724             else
0725                error(['Wrong scoring method (', [model_score_type], ') passed. Internal error.']);
0726             end
0727             
0728          end    
0729     
0730     
0731          if(n == n_iterations),
0732             final_score(i, this_set) = score;
0733                 % give the final score for the set if end is reached
0734          end
0735          
0736          score_for_iteration(i,n) = score;
0737                % record the score for this iteration and this image to be later
0738                % plotted for analysis
0739          if (strcmp(model_score_type, 'All')),
0740              all_scores_for_iteration(i,n,1) = all_scores(1);
0741              all_scores_for_iteration(i,n,2) = all_scores(2);
0742              all_scores_for_iteration(i,n,3) = all_scores(3);
0743          end    
0744          if ((strcmp(progress_indicator_type,'Progress Bar')) | (strcmp(progress_indicator_type,'Console Progress Bar'))),
0745            times(this_step) = toc;
0746            time_for_this_iteration = mean (times);
0747          end
0748         end  % end:images
0749       end  % end:iterations
0750       if (strcmp(progress_indicator_type,'Progress Bar')),
0751                 h = progressbar( h, 0, 'Finalising');
0752       end
0753       if (show_score_vs_iteration),
0754                     
0755 %           figure('Name', [[handle],[': Score versus iterations for every image warping step - objective function: '],[objective_function]]);
0756 %                  % create a new figure to show graph of optimisation for
0757 %                  % all steps and all images individually
0758 %           hold on;
0759 %           title('Score versus iterations for every image warping step');
0760 %           xlabel('Iteration number');
0761 %           ylabel('Score');
0762 %           for i=1:n_images,
0763 %                 plot(score_for_iteration(i,:));
0764 %           end;
0765 %           hold off;
0766 %
0767 %           figure('Name', [[handle],[': Score versus iterations - objective function: '],[objective_function]]);
0768 %                  % create a new figure to show graph of optimisation
0769 %           hold on;
0770 %           title('Score versus iterations');
0771 %           xlabel('Iteration number');
0772 %           ylabel('Mean score');
0773 %           for i=1:n_iterations,
0774 %              mean_score(i) = mean(score_for_iteration(:,i));
0775 %           end
0776 %           plot(mean_score);
0777 %           hold off;
0778           
0779           if (overlap_scores == 0),
0780              figure('Name', [[handle],[': Score versus image warping step - objective function: '],[objective_function]]);
0781                  % create a new figure to show graph of optimisation
0782           else
0783               
0784              figure(101);
0785           end
0786           
0787           hold on;
0788           
0789           if (strcmp(model_score_type, 'All')),
0790             title('Proportional score versus image warping step');
0791             xlabel('Warping Step');
0792             ylabel('% Change');  
0793             position_counter = 0;  
0794             for i=1:n_iterations,
0795               for j=1:n_images,
0796                 position_counter = position_counter + 1;
0797                 all_warp_step_score_vector(position_counter,1) = all_scores_for_iteration(j,i,1);
0798                 all_warp_step_score_vector(position_counter,2) = all_scores_for_iteration(j,i,2);
0799                 all_warp_step_score_vector(position_counter,3) = all_scores_for_iteration(j,i,3);
0800               end
0801             end
0802             all_warp_step_percent_vector(1,1) = 0;
0803                                % no change
0804             all_warp_step_percent_vector(2,1) = 0;
0805             all_warp_step_percent_vector(3,1) = 0;
0806                 
0807             for i = 2:n_iterations * n_images,
0808                     all_warp_step_percent_vector(1,i) = (all_warp_step_score_vector(i,1) - all_warp_step_score_vector(i-1,1)) / (all_warp_step_score_vector(i-1,1) + 0.001) * 100;
0809                     all_warp_step_percent_vector(2,i) = (all_warp_step_score_vector(i,2) - all_warp_step_score_vector(i-1,2)) / (all_warp_step_score_vector(i-1,2) + 0.001) * 100;
0810                     all_warp_step_percent_vector(3,i) = (all_warp_step_score_vector(i,3) - all_warp_step_score_vector(i-1,3)) / (all_warp_step_score_vector(i-1,3) + 0.001) * 100;              
0811             end          
0812           else
0813               title('Score versus image warping step');
0814               xlabel('Warping Step');
0815               ylabel('Score');
0816               position_counter = 0;
0817               for i=1:n_iterations,
0818                   for j=1:n_images,
0819                     position_counter = position_counter + 1;
0820                     warp_step_score_vector(position_counter) = score_for_iteration(j,i);
0821                   end
0822               end
0823           end
0824           if (run_all_objective_functions == 1),
0825               if strcmp(colour,'r'),
0826                 colour = 'g';
0827               elseif strcmp(colour,'g')
0828                 colour = 'b';
0829               else
0830                 colour = 'r';
0831               end 
0832               
0833               if strcmp(style,':'),
0834                 style = '-';
0835               elseif strcmp(style,'-')
0836                 style = '--';
0837               elseif strcmp(style,'--')
0838                 style = '-.'; 
0839               else
0840                 style = ':';
0841               end 
0842               plot(warp_step_score_vector,[[colour],[style]]);
0843               legend('Sequential MSD','Joint MSD','Sequential Model-based','Joint Model-based','Squential MI',...
0844                      'Joint MI', 'Sequential NMI', 'Joint NMI','Void');
0845           else
0846                 % if a normal single plot will suffice
0847                 if (strcmp(model_score_type, 'All')),
0848                          plot (all_warp_step_percent_vector(1,:), 'r');
0849                          plot (all_warp_step_percent_vector(2,:), 'g');
0850                          plot (all_warp_step_percent_vector(3,:), 'b');
0851                          legend('Specificity', 'Generalisability', 'Mean MSD');
0852                 else 
0853                          plot (warp_step_score_vector); 
0854                 end
0855                 if (show_target == 1),
0856                     Epsilon = 0.0001;
0857                     plot (repmat([log(Epsilon.^n_modes)], 1,n_iterations * n_images),'--');
0858                     legend('Current Evaluation','Log eigenvalues of perfectly registered images');
0859                 end
0860           end   
0861           hold off;
0862       end
0863       
0864       w_c_model = build_model(warped_images, warped_points, variation_kept, 'Optimised warp', weighting_normalisation_method, shape_weight);      
0865          % Smith: build model from warped images
0866       w_intensity_total_vars = w_c_model.intensity_model.total_var;
0867       w_shape_total_vars = w_c_model.shape_model.total_var;
0868          % get these two values to be used later
0869       model_score(this_set) = measure_model(w_c_model.variances, n_modes, model_evaluation_method, w_c_model);
0870       msd_score(this_set) = measure_model_msd(warped_images);
0871       shape_modes(this_set) = w_c_model.n_shape_modes;
0872       intensity_modes(this_set) = size(w_c_model.intensity_model.pcs,2);
0873       shape_variance(this_set) = sum(w_c_model.shape_model.variances);
0874       intensity_variance(this_set) = sum(w_c_model.intensity_model.variances);
0875          % copy some values to be displayed for statistics
0876       
0877       if (show_model_after_optimisation),
0878           show_combined_model(w_c_model,ref_points_vec, 2, 2, [[handle],[': Final combined model built from optimised warps - objective function: '],[objective_function]]);
0879       end
0880       
0881       if (show_specificity_statistics),
0882         [w_c_model.mean_specificity, w_c_model.std_specificity] = find_specificity(w_c_model, images, spec_iters, ref_points_vec);
0883         disp(' ');
0884         disp([['Objective function: '], [objective_function]]);
0885         disp(['Mean of specificity:               ', num2str(w_c_model.mean_specificity)]);
0886         disp(['Standard deviation of specificity: ', num2str(w_c_model.std_specificity)]);
0887       end
0888      
0889     
0890     % fig_title = 'Automatically aligned: ';
0891     % show_shape_model(w_shape_model, ref_points_vec, ref_image_vec, 2, white_width)
0892     % show_intensity_model(w_intensity_model, 2, white_width, fig_title)
0893     % show_combined_model(w_c_model, ref_points_vec, 2, white_width, fig_title)
0894     
0895     
0896     
0897     
0898     %%             END OF MODEL-BUILDING                    %%
0899     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0900     
0901     
0902     
0903     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0904     %% Now provide some statistics on the                   %%
0905     %% simulation/experiment                                %%
0906     
0907       
0908       %% Warping images, then modelling warped images    %%
0909     %% attempt to register images by warping.          %%
0910     
0911       if (plot_before_and_after),
0912         subplot_fig = figure('Name', [[handle],[': Left: Before registration; Right: After Registration - Objective function: '], [objective_function]]);
0913         H=figure(subplot_fig);
0914         for i=1:n_images,
0915            subplot(n_images, vertical_pane_location, (vertical_pane_location * i) - vertical_pane_location + 1);
0916            hold on;
0917            plot(images_before_offset(:,i));
0918            % title(['Unwarped image #',num2str(i)]);
0919            axis([0 image_width 0 1]);
0920            grid on;
0921            hold off;
0922         end
0923         if (apply_intensity_offset),
0924           for index = 1:n_images,
0925              peak (index) = max(images(:,index));
0926           end
0927           peak_reference = max (peak);  
0928           for index = 1:n_images,
0929             peak_difference = peak_reference - max(images(:,index));
0930             images(:,index) = images(:,index) + peak_difference;
0931             subplot(n_images, vertical_pane_location, (vertical_pane_location * index) - vertical_pane_location + 2);
0932             hold on;
0933             plot(images(:,index));
0934             % title(['Unwarped image #',num2str(i)]);
0935             axis([0 image_width 0 1]);
0936             grid on;
0937             hold off;
0938           end        
0939         end    
0940     
0941           % pass a void figure to the optimisation functions
0942         for i=1:n_images,
0943            subplot(n_images, vertical_pane_location, i * vertical_pane_location);
0944            hold on;
0945            plot(warped_images(:,i));
0946            % title(['Unwarped image #',num2str(i)]);
0947            axis([0 image_width 0 1]);
0948            grid on;
0949            hold off;
0950         end   
0951       else
0952         subplot_fig = 0; 
0953       end
0954     
0955       
0956  end % while
0957  
0958  t = toc;
0959       
0960  if (strcmp(progress_indicator_type,'Hierarchical Text')),
0961          disp(['Time for set ',num2str(this_set),': ',num2str(t)]);
0962  end
0963  time(this_set) = t;
0964  
0965 end % end set
0966 
0967 if (strcmp(progress_indicator_type,'Progress Bar')),
0968    progressbar( h,-1 );
0969       % destroy progress bar
0970 end
0971 
0972 if (produce_statistics == 1),
0973     disp(' ');
0974     disp(['======================================================']); 
0975     disp(['================= SET STATISTICS =====================']);
0976     disp(['| Objective function:                       ', objective_function]);
0977     disp(['| Mean of match score:                      ', num2str(mean(final_score(:)))]);    
0978     disp(['| Standard deviation of match score:        ', num2str(std(final_score(:)))]);
0979     disp(['| Mean of model score:                      ', num2str(mean(model_score(:)))]);    
0980     disp(['| Standard deviation of model score:        ', num2str(std(model_score(:)))]);
0981     disp(['| Mean of msd score:                        ', num2str(mean(msd_score(:)))]);
0982     disp(['| Standard deviation of msd score:          ', num2str(std(msd_score(:)))]);
0983     disp(['| Mean of shape modes:                      ', num2str(mean(shape_modes(:)))]);
0984     disp(['| Standard deviation of shape modes:        ', num2str(std(shape_modes(:)))]);
0985     disp(['| Mean of intensity modes:                  ', num2str(mean(intensity_modes(:)))]);
0986     disp(['| Standard deviation of intensity modes:    ', num2str(std(intensity_modes(:)))]);
0987     disp(['| Mean of shape variance:                   ', num2str(mean(shape_variance(:)))]);
0988     disp(['| Standard deviation of shape variance:     ', num2str(std(shape_variance(:)))]);        
0989     disp(['| Mean of intensity variance:               ', num2str(mean(intensity_variance(:)))]);    
0990     disp(['| Standard deviation of intensity variance: ', num2str(std(intensity_variance(:)))]);    
0991     disp(['| Mean time:                                ', num2str(mean(time(:)))]);    
0992     disp(['| Standard deviation of time:               ', num2str(std(time(:)))]);    
0993     t = toc;
0994          % get time from the counter initiated by <tic>
0995     disp(['| Total time:                               ',num2str(t)]);
0996          % display total time
0997     disp(['======================================================']); 
0998 end
0999 
1000 
1001 if (save_movie == 1)
1002   movie(M);
1003   movie2avi(M,movie_name);
1004   disp(' ');
1005   disp([movie_name, ' saved']);
1006           % process the movie and save it
1007   if (called_from_gui == 1),
1008       status = [[status];['(**) Video saved      '];['                      ']];
1009   end
1010 end
1011       
1012 if (error_found == 0),
1013               % if the error flag is not set
1014     if (called_from_gui == 1),
1015       status = [[status];['Registration Completed'];
1016              ['                      '];       
1017              ['Status: OK            ']];
1018          % send message
1019     else
1020       status = 'Status: OK'; 
1021          %indicate that everything was okay
1022     end
1023 elseif (error_found == 1),
1024     if (called_from_gui == 1),
1025       status = [[status];['Registration Completed'];
1026              ['                      '];       
1027              ['Status: Error         '];
1028              ['                      '];
1029              ['Operation Aborted     ']];
1030          % send message about error
1031     else
1032       status = 'Status: Operation Aborted'; 
1033          % indicate that something had gone wrong
1034     end    
1035 else
1036     if (called_from_gui == 1),
1037       status = [[status];['Registration Completed'];
1038              ['                      '];       
1039              ['Status: Error         '];
1040              ['                      '];
1041              ['Exit code unknown     ']];
1042          % send message about error
1043     else
1044       status = 'Status: Error'; 
1045          %indicate that something had gone wrong
1046     end
1047 end    
1048 
1049 %% END OF STATISTICS                                  %%
1050 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Generated on Thu 13-May-2004 18:00:46 by m2html © 2003