0001 function eval_obj_fn_to_mean
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 do_plot = 0;
0046 obj_fn_type = 'msd';
0047 n_images = 10;
0048 n_iterations = 10;
0049 n_sets = 10;
0050 image_width = 50;
0051 ref_shift = 0.2;
0052 max_shift = 0.2;
0053 step = 0.1;
0054 los = zeros(n_images,floor((max_shift-ref_shift)/step));
0055 his = zeros(n_images,floor((max_shift-ref_shift)/step));
0056 blurred = 0;
0057 spec_iters = 25;
0058 gen_iters = 25;
0059 min_error = 0;
0060 max_error = 1;
0061 error_step = 0.1;
0062 n_error_steps = (max_error-min_error)/error_step;
0063
0064 for this_set = 1:n_sets
0065 [imagelist images points his los] = make_1d_images(n_images, image_width, 0.2);
0066
0067 window = 9;
0068
0069
0070
0071
0072 points = -1 + 2*(points-1)/(image_width-1);
0073 los = -1 + 2*(los-1)/(image_width-1);
0074 his = -1 + 2*(his-1)/(image_width-1);
0075
0076 keep = 0.999999;
0077 ref_points_vec = points(:,1);
0078 ref_image_vec = images(:,1);
0079 if(strcmp(obj_fn_type,'model'))
0080 ref_hi = mean(his);
0081 ref_lo = mean(los);
0082 elseif(strcmp(obj_fn_type,'msd'))
0083 ref_hi = his(1);
0084 ref_lo = los(1);
0085 end
0086
0087
0088
0089
0090 if(do_plot)
0091 subplot_fig = figure;
0092 figure(subplot_fig),for i=1:n_images,subplot(n_images,2,(2*i)-1),plot(images(:,i)),title('Unwarped images'); end;
0093 end
0094 warped_images = images;
0095 warped_points = points;
0096
0097
0098 for n=1:n_iterations*2-1
0099 disp(['iter ',num2str(n)]);
0100
0101
0102 for i=1:n_images
0103 disp(['Warping image ',num2str(i),' of ',num2str(n_images)]);
0104 image_vec = images(:,i);
0105 points_vec = points(:,i);
0106 hi_step = (his(i)-ref_hi)/n_iterations;
0107 lo_step = (los(i)-ref_lo)/n_iterations;
0108 params.green = 'biharmCPS';
0109 [warped_points,E,data] = nrr_trans_1d(points_vec,[his(i),los(i)],[his(i)+hi_step*n, los(i)+lo_step*n],params,[]);
0110 warped_image = interp1(points_vec,image_vec,warped_points, 'linear',0);
0111
0112
0113 warped_images(:,i) = warped_image;
0114 warped_points(:,i) = warped_points;
0115 if(do_plot)
0116 figure(subplot_fig),subplot(10,2,2*i,'replace'),plot(warped_image); drawnow;
0117 pause(0.05);
0118 end
0119 end
0120
0121 if(strcmp(obj_fn_type,'model'))
0122 norm_type = 'edge';
0123 keep = 0.9999;
0124 c_model = build_model(warped_images, warped_points, keep, '', norm_type);
0125 obj_fn(n,this_set) = measure_model(c_model.variances,20);
0126 elseif(strcmp(obj_fn_type,'msd'))
0127 for i = 1:n_images
0128 temp(i) = msd(warped_images(:,i),ref_image_vec);
0129 end
0130 obj_fn(n,this_set) = mean(temp);
0131
0132 end
0133 end
0134 end
0135
0136
0137 figure,errorbar(log(mean(obj_fn,2)),std(obj_fn,0,2)./mean(obj_fn,2)),title([obj_fn_type, '(log)']);
0138
0139
0140