0001 function [param_list, warped_points, warped_image, score] = optimise_warps(ref_image, ref_points, unwarped_image, unwarped_points, spline_type, placement_method, n_points, verbose, do_plot, subplot_fig, pane)
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, ref_points, placement_method, n_points);
0052
0053
0054 if(do_plot)
0055 figure(subplot_fig),subplot(10,2,pane,'replace'),plot(unwarped_image); drawnow;
0056 end
0057
0058 warp_params.green = 'biharmCPS';
0059 param_list = [];
0060 start_image = unwarped_image;
0061 start_points = unwarped_points;
0062
0063
0064
0065 if(strcmp(spline_type,'single_point'))
0066 for i=1:size(grid,2)
0067 [params, score] = fminsearch(@eval_msd_cps_warp,[0],optimset('Display',verbose),grid(i),steps(i),start_points, start_image, ref_image, verbose);
0068
0069 param_list(size(param_list,1)+1).d = params;
0070 start_points = cps_warp_1d(start_points, grid(i), steps(i), params(1));
0071 start_image = interp1(ref_points,unwarped_image,start_points, 'linear',0);
0072
0073 last_score = score;
0074 end
0075 elseif(strcmp(spline_type,'multi_point'))
0076 warped_grid = grid;
0077 warp_params.green = 'biharmCPS';
0078 last_score = eval_msd_multi_warp(zeros(size(grid)),grid, unwarped_image, unwarped_points, ref_image, ref_points, 20, warp_params);
0079 [params, score] = fminsearch(@eval_msd_multi_warp,zeros(size(grid)),optimset('Display',verbose,'TolX',1e-10),grid, unwarped_image, unwarped_points, ref_image, ref_points, 20, warp_params);
0080 param_list(size(param_list,1)+1,:).d = params;
0081 warped_grid = grid + params;
0082 start_points = nrr_trans_1d(start_points, grid, warped_grid, warp_params,[]);
0083 start_image = interp1(unwarped_points,unwarped_image,start_points, 'linear',0);
0084
0085 disp(['Initial score: ',num2str(last_score),' Final score: ',num2str(score)]);
0086
0087 end
0088
0089 warped_points = start_points;
0090 warped_image = start_image;
0091 if(do_plot)
0092 figure(subplot_fig),subplot(10,2,pane,'replace'),plot(warped_image); drawnow;
0093 end