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