Home > Source > Evaluate_Objective > eval_obj_fn_to_mean.m

eval_obj_fn_to_mean

PURPOSE ^

==============================================================

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 % ==============================================================
0003 % EVAL_OBJ_FN_TO_MEAN: Evaluate objective function for the mean.
0004 %
0005 % Code written by Katherine Smith, 2003
0006 %
0007 %    GENERAL
0008 %
0009 %      eval_obj_fn_to_mean
0010 %
0011 %    INPUT/S
0012 %
0013 %      -
0014 %
0015 %    OUTPUT/S
0016 %
0017 %      -
0018 %
0019 %    PENDING WORK
0020 %
0021 %      -
0022 %
0023 %    KNOWN BUG/S
0024 %
0025 %      -
0026 %
0027 %    COMMENT/S
0028 %
0029 %
0030 %
0031 %    RELATED FUNCTION/S
0032 %
0033 %
0034 %
0035 %    ABOUT
0036 %
0037 %      -Created:     November 23rd, 2003
0038 %      -Last update: Novermber 30th, 2003
0039 %      -Revision:    0.0.1
0040 %      -Author:      R. S. Schestowitz, University of Manchester
0041 % ==============================================================
0042 
0043 % make images and points
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     % smooth images
0067     window = 9;
0068     %    images = average_smooth(images, window); blurred = 1;
0069     %    images = gaussian_smooth(images, window); blurred = 1;
0070     
0071     % normalise points from -1 to 1
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     % Warping images, then modelling warped images
0089     % attempt to register images by warping.
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     % move points iteratively towards mean
0098   for n=1:n_iterations*2-1
0099     disp(['iter ',num2str(n)]);
0100     % correct registration
0101     % attempt to register
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 %      [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);
0112           % Warps are being applied.
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         % rename these variabled e.g. temp
0132     end
0133   end % n_iterations
0134 end % n_sets
0135 
0136 % logged
0137 figure,errorbar(log(mean(obj_fn,2)),std(obj_fn,0,2)./mean(obj_fn,2)),title([obj_fn_type, '(log)']);
0138 
0139 % not logged
0140 %figure,errorbar(mean(obj_fn,2)),std(obj_fn,0,2),title(obj_fn_type);

Generated on Thu 13-May-2004 18:00:46 by m2html © 2003