Home > Source > Evaluate_Objective > eval_obj_fn_to_mean.m

eval_obj_fn_to_mean

PURPOSE ^

EVAL_OBJ_FN_TO_MEAN: Evaluate objective function for the mean.

SYNOPSIS ^

function eval_obj_fn_to_mean

DESCRIPTION ^

 EVAL_OBJ_FN_TO_MEAN: Evaluate objective function for the mean.

 Code written by Katherine Smith, 2003

    GENERAL

      eval_obj_fn_to_mean

    INPUT/S

      -
           
    OUTPUT/S

      -

    PENDING WORK

      -

    KNOWN BUG/S

      -

    COMMENT/S

      

    RELATED FUNCTION/S

      

    ABOUT

      -Created:     November 23rd, 2003
      -Last update: Novermber 30th, 2003
      -Revision:    0.0.1
      -Author:      R. S. Schestowitz, University of Manchester
 ==============================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function eval_obj_fn_to_mean
0002 % EVAL_OBJ_FN_TO_MEAN: Evaluate objective function for the mean.
0003 %
0004 % Code written by Katherine Smith, 2003
0005 %
0006 %    GENERAL
0007 %
0008 %      eval_obj_fn_to_mean
0009 %
0010 %    INPUT/S
0011 %
0012 %      -
0013 %
0014 %    OUTPUT/S
0015 %
0016 %      -
0017 %
0018 %    PENDING WORK
0019 %
0020 %      -
0021 %
0022 %    KNOWN BUG/S
0023 %
0024 %      -
0025 %
0026 %    COMMENT/S
0027 %
0028 %
0029 %
0030 %    RELATED FUNCTION/S
0031 %
0032 %
0033 %
0034 %    ABOUT
0035 %
0036 %      -Created:     November 23rd, 2003
0037 %      -Last update: Novermber 30th, 2003
0038 %      -Revision:    0.0.1
0039 %      -Author:      R. S. Schestowitz, University of Manchester
0040 % ==============================================================
0041 
0042 % make images and points
0043 
0044 do_plot = 0;
0045 obj_fn_type = 'msd';
0046 n_images = 10;
0047 n_iterations = 10;
0048 n_sets = 10;
0049 image_width = 50;
0050 ref_shift = 0.2;
0051 max_shift = 0.2;
0052 step = 0.1;
0053 los = zeros(n_images,floor((max_shift-ref_shift)/step));
0054 his = zeros(n_images,floor((max_shift-ref_shift)/step));
0055 blurred = 0;
0056 spec_iters = 25;
0057 gen_iters = 25;
0058 min_error = 0;
0059 max_error = 1;
0060 error_step = 0.1;
0061 n_error_steps = (max_error-min_error)/error_step;
0062 
0063 for this_set = 1:n_sets
0064     [imagelist images points his los] = make_1d_images(n_images, image_width, 0.2);
0065     % smooth images
0066     window = 9;
0067     %    images = average_smooth(images, window); blurred = 1;
0068     %    images = gaussian_smooth(images, window); blurred = 1;
0069     
0070     % normalise points from -1 to 1
0071     points = -1 + 2*(points-1)/(image_width-1);
0072     los = -1 + 2*(los-1)/(image_width-1);
0073     his = -1 + 2*(his-1)/(image_width-1);
0074         
0075     keep = 0.999999;
0076     ref_points_vec = points(:,1);
0077     ref_image_vec = images(:,1);
0078     if(strcmp(obj_fn_type,'model'))
0079         ref_hi = mean(his);
0080         ref_lo = mean(los);
0081     elseif(strcmp(obj_fn_type,'msd'))
0082         ref_hi = his(1);
0083         ref_lo = los(1);
0084     end
0085     
0086     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0087     % Warping images, then modelling warped images
0088     % attempt to register images by warping.
0089   if(do_plot)
0090       subplot_fig = figure;
0091       figure(subplot_fig),for i=1:n_images,subplot(n_images,2,(2*i)-1),plot(images(:,i)),title('Unwarped images'); end;
0092   end
0093   warped_images = images;
0094   warped_points = points;
0095     
0096     % move points iteratively towards mean
0097   for n=1:n_iterations*2-1
0098     disp(['iter ',num2str(n)]);
0099     % correct registration
0100     % attempt to register
0101     for i=1:n_images
0102       disp(['Warping image ',num2str(i),' of ',num2str(n_images)]);
0103       image_vec = images(:,i);
0104       points_vec = points(:,i);
0105       hi_step = (his(i)-ref_hi)/n_iterations;
0106       lo_step = (los(i)-ref_lo)/n_iterations;
0107       params.green = 'biharmCPS';
0108       [warped_points,E,data] = nrr_trans_1d(points_vec,[his(i),los(i)],[his(i)+hi_step*n, los(i)+lo_step*n],params,[]);
0109       warped_image = interp1(points_vec,image_vec,warped_points, 'linear',0);
0110 %      [param_list, warped_point, warped_image, score] = optimise_warps(ref_image_vec, ref_points_vec, image_vec, points_vec, 'multi_point', 'edge',subplot_fig,i*2);
0111           % Warps are being applied.
0112       warped_images(:,i) = warped_image;
0113       warped_points(:,i) = warped_points;
0114       if(do_plot)
0115         figure(subplot_fig),subplot(10,2,2*i,'replace'),plot(warped_image); drawnow;
0116         pause(0.05);
0117       end
0118     end
0119       
0120     if(strcmp(obj_fn_type,'model'))
0121         norm_type = 'edge';
0122         keep = 0.9999;
0123         c_model = build_model(warped_images, warped_points, keep, '', norm_type);
0124         obj_fn(n,this_set) = measure_model(c_model.variances,20);
0125     elseif(strcmp(obj_fn_type,'msd'))
0126           for i = 1:n_images
0127             temp(i) = msd(warped_images(:,i),ref_image_vec);
0128           end
0129         obj_fn(n,this_set) = mean(temp);
0130         % rename these variabled e.g. temp
0131     end
0132   end % n_iterations
0133 end % n_sets
0134 
0135 % logged
0136 figure,errorbar(log(mean(obj_fn,2)),std(obj_fn,0,2)./mean(obj_fn,2)),title([obj_fn_type, '(log)']);
0137 
0138 % not logged
0139 %figure,errorbar(mean(obj_fn,2)),std(obj_fn,0,2),title(obj_fn_type);

Generated on Fri 14-May-2004 10:05:30 by m2html © 2003