Home > Source > Optimise > Model_Based > optimise_all_warps_model.m

optimise_all_warps_model

PURPOSE ^

OPTIMISE_ALL_WARPS_MDOEL:

SYNOPSIS ^

function [param_list, warped_points, warped_image, score] = optimise_all_warps_model(ref_image, ref_points, unwarped_image, unwarped_points, spline_type, placement_method, n_points, verbose, do_plot, subplot_fig, pane, column, image_width, number_of_images, verbose_score, model_evaluation_method, n_modes, weighting_normalisation_method, shape_weight, variation_kept, show_warps_while_optimising, precision_required); %use_parameters, parameters)

DESCRIPTION ^

 OPTIMISE_ALL_WARPS_MDOEL: 

 Code written by Katherine Smith, 2003

    GENERAL

      [param_list, warped_points, warped_image, score] = 
          optimise_all_warps_model(ref_image, ref_points, unwarped_image, 
          unwarped_points, spline_type, placement_method, n_points, verbose, 
          do_plot, subplot_fig, pane,
          image_width, number_of_images, verbose_score)
 
    INPUT/S

      -X:
          X
           
    OUTPUT/S

      -X:
           X

    PENDING WORK
      
      

    KNOWN BUG/S

      

    COMMENT/S

      

    RELATED FUNCTION/S

      

    ABOUT

      -Created:     November 23rd, 2003
      -Last update: January 23rd,  2004
      -Revision:    0.1.5
      -Author:      R. S. Schestowitz, University of Manchester
 ==============================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [param_list, warped_points, warped_image, score] = optimise_all_warps_model(ref_image, ref_points, unwarped_image, unwarped_points, spline_type, placement_method, n_points, verbose, do_plot, subplot_fig, pane, column, image_width, number_of_images, verbose_score, model_evaluation_method, n_modes, weighting_normalisation_method, shape_weight, variation_kept, show_warps_while_optimising, precision_required); %use_parameters, parameters)
0002 % OPTIMISE_ALL_WARPS_MDOEL:
0003 %
0004 % Code written by Katherine Smith, 2003
0005 %
0006 %    GENERAL
0007 %
0008 %      [param_list, warped_points, warped_image, score] =
0009 %          optimise_all_warps_model(ref_image, ref_points, unwarped_image,
0010 %          unwarped_points, spline_type, placement_method, n_points, verbose,
0011 %          do_plot, subplot_fig, pane,
0012 %          image_width, number_of_images, verbose_score)
0013 %
0014 %    INPUT/S
0015 %
0016 %      -X:
0017 %          X
0018 %
0019 %    OUTPUT/S
0020 %
0021 %      -X:
0022 %           X
0023 %
0024 %    PENDING WORK
0025 %
0026 %
0027 %
0028 %    KNOWN BUG/S
0029 %
0030 %
0031 %
0032 %    COMMENT/S
0033 %
0034 %
0035 %
0036 %    RELATED FUNCTION/S
0037 %
0038 %
0039 %
0040 %    ABOUT
0041 %
0042 %      -Created:     November 23rd, 2003
0043 %      -Last update: January 23rd,  2004
0044 %      -Revision:    0.1.5
0045 %      -Author:      R. S. Schestowitz, University of Manchester
0046 % ==============================================================
0047 
0048 
0049 % figure(3);
0050 % hold on
0051 % plot(unwarped_image)
0052 % hold off     ** Image is dynamic
0053 [grid, steps] = setup_grid(2, unwarped_image, ref_points, placement_method, n_points);
0054 
0055 % POSSIBLE OPTIMISATION: where no randomisation is applied for grid
0056 % selection, e.g. 'overlap grid' and 'grid', the grid needs to be set up ONCE, not every
0057 % iteration. A test for this needs to be put outside this function to avoid
0058 % unnecessary computations.
0059 
0060 if (do_plot),
0061   figure(subplot_fig);
0062   subplot(number_of_images, column ,pane , 'replace');
0063   plot(unwarped_image);
0064   axis([0 image_width 0 1]);
0065   drawnow;
0066 end
0067 
0068 warp_params.green = 'biharmCPS';
0069 
0070 
0071 % added 16/03/04
0072 % if (~use_parameters),
0073 %   param_list.d = [0,0,0,0,0];
0074 % else
0075 %   for i=1:size(grid),
0076 %     param_list.d(i) = parameters.d(i);
0077 %   end
0078 % end
0079 % if (use_parameters),
0080 % parameters.d
0081 % end
0082 
0083 
0084 % 16/03/04:param_list = [];
0085 % also remove 2 last arguments of this function
0086 
0087 param_list = [];
0088 start_image = unwarped_image;
0089 start_points = unwarped_points;
0090 
0091 %last_score = msd(ref_image, unwarped_image);
0092 
0093 
0094 if (strcmp(spline_type,'single_point')),
0095 
0096     
0097       %     steps
0098       %     grid
0099       %     size(grid)
0100   
0101 
0102   last_score = eval_model_cps_warp(zeros(size(grid)), grid, steps, unwarped_image, unwarped_points, ref_image, ref_points, n_modes, start_points, model_evaluation_method, weighting_normalisation_method, shape_weight, variation_kept, show_warps_while_optimising);  
0103       % last_score
0104   
0105       % if (~use_parameters),
0106    
0107   
0108 [params, score] = fminsearch(@eval_model_cps_warp, zeros(size(grid),1), optimset('Display', verbose, 'TolX', precision_required) , grid, steps, start_image, start_points, ref_image, ref_points, n_modes, start_points, model_evaluation_method, weighting_normalisation_method, shape_weight, variation_kept, show_warps_while_optimising);     
0109 
0110 
0111 % 'MaxIter', 1000
0112 % str2num([['1e-'],[num2str(ceil(rand*100))]])
0113 %   score
0114 %   params=0.1;
0115 %   [score1,start_points] = eval_model_cps_warp(params, grid, steps, start_image, start_points, ref_image, ref_points, n_modes, start_points, model_evaluation_method, weighting_normalisation_method, shape_weight, variation_kept, show_warps_while_optimising);
0116 %   score1
0117 %   params=0.2;
0118 %   [score2,start_points] = eval_model_cps_warp(params, grid, steps, start_image, start_points, ref_image, ref_points, n_modes, start_points, model_evaluation_method, weighting_normalisation_method, shape_weight, variation_kept, show_warps_while_optimising);
0119 %   score2
0120 %   params=0.2;
0121 %   [score2,start_points] = eval_model_cps_warp(params, grid, steps, start_image, start_points, ref_image, ref_points, n_modes, start_points, model_evaluation_method, weighting_normalisation_method, shape_weight, variation_kept, show_warps_while_optimising);
0122 %   score2
0123 %   params=0.3;
0124 %   [score3,start_points] = eval_model_cps_warp(params, grid, steps, start_image, start_points, ref_image, ref_points, n_modes, start_points, model_evaluation_method, weighting_normalisation_method, shape_weight, variation_kept, show_warps_while_optimising);
0125 %   score3
0126 %   params=0.4;
0127 %   [score4,start_points] = eval_model_cps_warp(params, grid, steps, start_image, start_points, ref_image, ref_points, n_modes, start_points, model_evaluation_method, weighting_normalisation_method, shape_weight, variation_kept, show_warps_while_optimising);
0128 %   score4
0129 %   params=0.5;
0130 %   [score5,start_points] = eval_model_cps_warp(params, grid, steps, start_image, start_points, ref_image, ref_points, n_modes, start_points, model_evaluation_method, weighting_normalisation_method, shape_weight, variation_kept, show_warps_while_optimising);
0131 %   score5
0132       % else
0133       % [params, score] = fminsearch(@eval_model_cps_warp,parameters.d,optimset('Display',verbose),grid,steps,start_image, start_points, ref_image, ref_points, n_modes, start_points, model_evaluation_method, weighting_normalisation_method, shape_weight, variation_kept);
0134       %  end
0135       % try randn(size(grid),1)
0136   param_list(size(param_list,1)+1).d = params;
0137   [dummy,start_points] = eval_model_cps_warp(params, grid, steps, start_image, start_points, ref_image, ref_points, n_modes, start_points, model_evaluation_method, weighting_normalisation_method, shape_weight, variation_kept, show_warps_while_optimising);
0138   start_image = interp1(unwarped_points, unwarped_image, start_points, 'linear',0); 
0139   
0140   
0141   
0142   
0143 elseif (strcmp(spline_type,'multi_point')),
0144   warped_grid = grid;
0145   last_score = eval_model_multi_warp(zeros(size(grid)), grid, unwarped_image, unwarped_points, ref_image, ref_points, n_modes, start_points, warp_params, model_evaluation_method, weighting_normalisation_method, shape_weight, variation_kept, show_warps_while_optimising);
0146   [params, score] = fminsearch(@eval_model_multi_warp, zeros(size(grid)), optimset('Display', verbose, 'TolX', precision_required), grid, unwarped_image, unwarped_points, ref_image, ref_points, n_modes, start_points, warp_params, model_evaluation_method, weighting_normalisation_method, shape_weight, variation_kept, show_warps_while_optimising);
0147   param_list(size(param_list,1)+1,:).d = params;
0148   warped_grid = grid + params;
0149   start_points = nrr_trans_1d(start_points, grid, warped_grid, warp_params,[]);
0150   start_image = interp1(unwarped_points,unwarped_image,start_points, 'linear',0);
0151   
0152   
0153 else
0154   error('Unknown spline type');  
0155 end
0156 
0157 
0158 
0159 
0160 if (verbose_score == 1),
0161     disp(['Initial score: ',num2str(last_score),' Final score: ', num2str(score), ' Difference: ', num2str(last_score - score)]);
0162 end
0163 
0164 warped_points = start_points;
0165 warped_image = start_image;
0166 
0167 if (do_plot),
0168   figure(subplot_fig);
0169   subplot(number_of_images, column , pane, 'replace');
0170   plot(warped_image);
0171   axis([0 image_width 0 1]);
0172   title(num2str(score));
0173   drawnow;
0174 end

Generated on Fri 14-May-2004 10:05:30 by m2html © 2003