Home > Source > Redundancy > build_1d_model_2_bump.m

build_1d_model_2_bump

PURPOSE ^

% SEEMS UNFINISHED... MAYBE JUST SUBROUTINE.. KATE SAYS IT MAY BE REDUNDANT

SYNOPSIS ^

function build_1d_model_2_bump

DESCRIPTION ^

% SEEMS UNFINISHED... MAYBE JUST SUBROUTINE.. KATE SAYS IT MAY BE REDUNDANT
% AND IS MOSTLY MADE OF CUT-AND-PASTE

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function build_1d_model_2_bump
0002 
0003 %% SEEMS UNFINISHED... MAYBE JUST SUBROUTINE.. KATE SAYS IT MAY BE REDUNDANT
0004 %% AND IS MOSTLY MADE OF CUT-AND-PASTE
0005 
0006 % make images and points
0007 n_images = 10;
0008 n_iterations = 1;
0009 n_sets = 10;
0010 image_width = 100;
0011 spline_type = 'multi_point';
0012 placement_type = 'random';
0013 n_points = 5;
0014 do_plot = 0;
0015 
0016 white_ctr = 0;
0017 ref_shift = 0.2;
0018 max_shift = 0.2;
0019 step = 0.1;
0020 los = zeros(n_images,floor((max_shift-ref_shift)/step));
0021 his = zeros(n_images,floor((max_shift-ref_shift)/step));
0022 factor_step = 0.1;
0023 factor_min = 0;
0024 factor_max = 0.4;
0025 blurred = 0;
0026 spec_iters = 25;
0027 gen_iters = 25;
0028 min_error = 0;
0029 max_error = 1;
0030 error_step = 0.1;
0031 n_error_steps = (max_error-min_error)/error_step;
0032 
0033 tic;
0034 for this_set = 1:n_sets
0035   tic;
0036   ['calculating set ', num2str(this_set)]
0037   % for each set of n_sets images, build a model
0038   % calculate obj fn values from these models, plot the mean with error
0039   % bars given by 1 stddev away
0040   for white_width = ref_shift:step:max_shift
0041     white_ctr = white_ctr+1;
0042 
0043     [imagelist1 images1 points1 his1(:,white_ctr) los1(:,white_ctr)] = make_1d_images(n_images, image_width/2, white_width);
0044     [imagelist2 images2 points2 his2(:,white_ctr) los2(:,white_ctr)] = make_1d_images(n_images, image_width/2, white_width);
0045     images = vertcat(images1, images2);
0046     points = vertcat(points1, points2+image_width/2);
0047     his = vertcat(his1, his2);
0048     los = vertcat(los1, los2);
0049     % smooth images
0050     window = 9;
0051 %    images = average_smooth(images, window); blurred = 1;
0052 %    images = gaussian_smooth(images, window); blurred = 1;
0053 
0054     % normalise points from -1 to 1
0055     points = -1 + 2*(points-1)/(image_width-1);
0056 
0057     keep = 0.999999;
0058     ref_points_vec = points(:,1);
0059     ref_image_vec = images(:,1);
0060     ref_hi = his(1);
0061     ref_lo = los(1);
0062     
0063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0064 % Warping images, then modelling warped images
0065 % attempt to register images by warping.
0066 subplot_fig = figure;
0067 figure(subplot_fig),for i=1:n_images,subplot(n_images,2,(2*i)-1),plot(images(:,i)),title('Unwarped images'); end;
0068 warped_images = images;
0069 warped_points = points;
0070 % correctly_warped_points = points;
0071 % correctly_warped_images = images;
0072 % for i=1:n_images
0073 %   % now bung in the right deformations to get them back
0074 %   correctly_warped_points(:,i) = linear_warp(ref_points_vec, los(i,white_ctr), his(i,white_ctr), ref_lo, ref_hi);
0075 %   correctly_warped_points_vec = correctly_warped_points(:,i);
0076 %   image_vec = images(:,i);
0077 %   % resample at the warped points - point on reg. grid has value of point at same index in warpy grid
0078 %   % need to interpolate
0079 %   correctly_warped_images(:,i) = interp1(ref_points_vec, image_vec, correctly_warped_points_vec);
0080 %   correct_model = build_model(correctly_warped_images,correctly_warped_points,1,'','edge',0);
0081 %   converging_score(i) = measure_model(correct_model.variances,50);
0082 % end
0083 % figure,plot(log(converging_score)),title('Log of score as model converges');
0084 %
0085 
0086   for n=1:n_iterations
0087   disp(['iter ',num2str(n)]);
0088     % correct registration
0089     % attempt to register
0090     for i=1:n_images
0091       disp(['Warping image ',num2str(i),' of ',num2str(n_images)]);
0092       image_vec = warped_images(:,i);
0093       points_vec = warped_points(:,i);
0094 %      [param_list, warped_point, warped_image, score] = optimise_warps_model([warped_images(:,1:i-1),warped_images(:,i+1:n_images)], [warped_points(:,1:i-1),warped_points(:,i+1:n_images)], image_vec, points_vec,placement_type,spline_type,subplot_fig,i*2, n_points);
0095       [param_list, warped_point, warped_image, score] = optimise_all_warps(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type,subplot_fig,i*2, n_points);
0096 %      [param_list, warped_point, warped_image, score] = optimise_warps(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points);
0097 
0098       warped_images(:,i) = warped_image;
0099       warped_points(:,i) = warped_point;
0100 
0101 %      figure(subplot_fig),title(['Warped images, after image ',num2str(i),' iteration ',num2str(n)]);
0102       %      dummy = waitforbuttonpress;
0103       if(n==n_iterations)
0104         final_score(i, this_set) = score;
0105       end
0106     end
0107   end
0108 
0109     % build model from warped images
0110     w_c_model = build_model(warped_images, warped_points, keep,'Optimised warp', 'variance');
0111 %    [w_c_model.mean_specificity, w_c_model.std_specificity] = find_specificity(w_c_model, images, spec_iters, ref_points_vec);
0112 %    show_combined_model(w_c_model,ref_points_vec, 2, 0.2, 'Combined model built from optimised warps');
0113 
0114   fig_title = 'Automatically aligned: ';
0115 %  show_shape_model(w_shape_model, ref_points_vec, ref_image_vec, 2, white_width)
0116 %  show_intensity_model(w_intensity_model, 2, white_width, fig_title)
0117 %  show_combined_model(w_c_model, ref_points_vec, 2, white_width, fig_title)
0118 
0119     w_intensity_total_vars(white_ctr) = w_c_model.intensity_model.total_var;
0120     w_shape_total_vars(white_ctr) = w_c_model.shape_model.total_var;
0121 
0122     warped_score(white_ctr, this_set) = measure_model(w_c_model.variances, 20);
0123     shape_modes(white_ctr, this_set) = w_c_model.n_shape_modes;
0124     intensity_modes(white_ctr, this_set) = size(w_c_model.intensity_model.pcs,2);
0125     shape_variance(white_ctr, this_set) = sum(w_c_model.shape_model.variances);
0126     intensity_variance(white_ctr, this_set) = sum(w_c_model.intensity_model.variances);
0127     white_ctr = 1;
0128   end % white width
0129   t = toc;
0130   disp(['Time for set ',num2str(this_set),': ',num2str(t)]);
0131 end % set
0132 disp('Mean match score:');
0133 mean(final_score(:))
0134 disp('Std match score:');
0135 std(final_score(:))
0136 
0137 disp('Mean model score:');
0138 mean(warped_score(:))
0139 disp('Std model score:');
0140 std(warped_score(:))
0141 
0142 disp('Mean shape modes:');
0143 mean(shape_modes(:))
0144 disp('Std shape modes:');
0145 std(shape_modes(:))
0146 
0147 disp('Mean intensity modes:');
0148 mean(intensity_modes(:))
0149 disp('Std intensity modes:');
0150 std(intensity_modes(:))
0151 
0152 disp('Mean shape variance:');
0153 mean(shape_variance(:))
0154 disp('Std shape variance:');
0155 std(shape_variance(:))
0156 
0157 disp('Mean intensity variance:');
0158 mean(intensity_variance(:))
0159 disp('Std intensity variance:');
0160 std(intensity_variance(:))
0161 
0162 t = toc;
0163 disp(['Total time: ',num2str(t)]);

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