0001 function [param_list, warped_points, warped_image, score] = optimise_warps_model(image_set, points_set, 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)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 [grid, steps] = setup_grid(2, unwarped_image, unwarped_points, placement_method, n_points);
0052
0053 if (do_plot),
0054 figure(subplot_fig);
0055 subplot(number_of_images, column, pane, 'replace');
0056 plot(unwarped_image);
0057 axis([0 image_width 0 1]);
0058 drawnow;
0059 end
0060
0061 start_points = unwarped_points;
0062
0063 param_list = [];
0064 start_image = unwarped_image;
0065
0066 if(strcmp(spline_type,'single_point')),
0067 last_score = eval_model_cps_warp([0],grid(1),steps(1), unwarped_image, unwarped_points, image_set, points_set, n_modes, start_points, model_evaluation_method, weighting_normalisation_method, shape_weight, variation_kept, show_warps_while_optimising);
0068 for i=1:size(grid)
0069 [params, score] = fminsearch(@eval_model_cps_warp, [0], optimset('Display', verbose, 'TolX', precision_required), grid(i),steps(i), unwarped_image, unwarped_points, image_set, points_set, n_modes, start_points, model_evaluation_method, weighting_normalisation_method, shape_weight, variation_kept, show_warps_while_optimising);
0070 param_list(size(param_list,1) + 1,:).d = params * steps(i);
0071 param_list(size(param_list,1),:).r = steps(i);
0072 param_list(size(param_list,1),:).centre = grid(i);
0073 start_points = cps_warp_1d(start_points, grid(i), steps(i), params);
0074 start_image = interp1(unwarped_points,unwarped_image,start_points, 'linear',0);
0075 end
0076 warped_points = start_points;
0077 warped_image = start_image;
0078 elseif(strcmp(spline_type,'multi_point')),
0079 warped_grid = grid;
0080 warp_params.green = 'biharmCPS';
0081 last_score = eval_model_multi_warp(zeros(size(grid)),grid,unwarped_image, unwarped_points, image_set, points_set, n_modes, start_points, warp_params, model_evaluation_method, weighting_normalisation_method, shape_weight, variation_kept, show_warps_while_optimising);
0082 [params,score, data] = fminsearch(@eval_model_multi_warp,zeros(size(grid)),optimset('Display', verbose, 'TolX', precision_required),warped_grid,unwarped_image, unwarped_points, image_set, points_set, n_modes, start_points, warp_params, model_evaluation_method, weighting_normalisation_method, shape_weight, variation_kept, show_warps_while_optimising);
0083 param_list(size(param_list,1) + 1,:).d = params;
0084 warped_grid = grid + params;
0085 warped_points = nrr_trans_1d(start_points, grid, warped_grid, warp_params,[]);
0086 warped_image = interp1(unwarped_points,unwarped_image,warped_points, 'linear',0);
0087 else
0088 error('Unknown spline type');
0089 end
0090
0091 if (verbose_score == 1),
0092 disp(['Initial score: ', num2str(last_score), ' Final score: ', num2str(score), ' Difference: ', num2str(last_score - score)]);
0093 end
0094
0095 if (do_plot),
0096 figure(subplot_fig);
0097 subplot(number_of_images, column ,pane,'replace');
0098 plot(warped_image);
0099 axis([0 image_width 0 1]);
0100 title(num2str(score));
0101 drawnow;
0102 end