0001 function build_1d_model_2_bump
0002
0003
0004
0005
0006
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
0038
0039
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
0050 window = 9;
0051
0052
0053
0054
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
0065
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
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086 for n=1:n_iterations
0087 disp(['iter ',num2str(n)]);
0088
0089
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
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
0097
0098 warped_images(:,i) = warped_image;
0099 warped_points(:,i) = warped_point;
0100
0101
0102
0103 if(n==n_iterations)
0104 final_score(i, this_set) = score;
0105 end
0106 end
0107 end
0108
0109
0110 w_c_model = build_model(warped_images, warped_points, keep,'Optimised warp', 'variance');
0111
0112
0113
0114 fig_title = 'Automatically aligned: ';
0115
0116
0117
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
0129 t = toc;
0130 disp(['Time for set ',num2str(this_set),': ',num2str(t)]);
0131 end
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)]);