0001 function [param_list, warped_points, warped_image, score] = optimise_wavelet(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, wavelet_evalution_method, filter, filter_level, 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 [grid, steps] = setup_grid(2, unwarped_image, ref_points, placement_method, n_points);
0042
0043 if (do_plot),
0044 figure(subplot_fig);
0045 subplot(number_of_images, column ,pane , 'replace');
0046 plot(unwarped_image);
0047 axis([0 image_width 0 1]);
0048 drawnow;
0049 end
0050
0051 warp_params.green = 'biharmCPS';
0052 param_list = [];
0053 start_image = unwarped_image;
0054 start_points = unwarped_points;
0055
0056 if(strcmp(spline_type,'single_point'))
0057 last_score = eval_wavelet_single_point(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, wavelet_evalution_method, filter, filter_level);
0058 [params, score] = fminsearch(@eval_wavelet_single_point,zeros(size(grid)),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, wavelet_evalution_method, filter, filter_level);
0059 param_list(size(param_list,1)+1).d = params;
0060 [dummy,start_points] = eval_wavelet_single_point(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, wavelet_evalution_method, filter, filter_level);
0061 start_image = interp1(unwarped_points,unwarped_image,start_points, 'linear',0);
0062 elseif(strcmp(spline_type,'multi_point'))
0063 warped_grid = grid;
0064 warp_params.green = 'biharmCPS';
0065 last_score = eval_wavelet_multi_point(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, wavelet_evalution_method, filter, filter_level);
0066 [params, score] = fminsearch(@eval_wavelet_multi_point,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, wavelet_evalution_method, filter, filter_level);
0067 param_list(size(param_list,1)+1,:).d = params;
0068 warped_grid = grid + params;
0069 start_points = nrr_trans_1d(start_points, grid, warped_grid, warp_params,[]);
0070 start_image = interp1(unwarped_points,unwarped_image,start_points, 'linear',0);
0071 else
0072 error('Unknown spline type');
0073 end
0074
0075
0076 if (verbose_score == 1),
0077 disp(['Initial score: ',num2str(last_score),' Final score: ', num2str(score), ' Difference: ', num2str(last_score - score)]);
0078 end
0079
0080 warped_points = start_points;
0081 warped_image = start_image;
0082
0083
0084 if (do_plot),
0085 figure(subplot_fig);
0086 subplot(number_of_images, column , pane, 'replace');
0087 plot(warped_image);
0088 axis([0 image_width 0 1]);
0089 title(num2str(score));
0090 drawnow;
0091 end