0001 function [status] = build_1d_bump_model( ...
0002 spline_type, placement_type, objective_function, ...
0003 apply_intensity_offset, save_movie, do_plot, movie_type, ...
0004 progress_bar, user_menu, produce_statistics, ...
0005 see_model_before_each_iteration, show_pixels, show_score_vs_iteration, ...
0006 show_model_after_optimisation, show_specificity_statistics, verbose_score, ...
0007 movie_name, window, average_smooth_enabled, gaussian_smooth_enabled, ...
0008 bump_width, bump_width_variation, bump_height, bump_height_variation, ...
0009 bump_position_freedom, initial_diminish_factor, smoothness_factor, ...
0010 plot_before_and_after, number_of_bins, model_evaluation_method, ...
0011 show_score_using_model, handle, n_modes, shape_weight, ...
0012 weighting_normalisation_method, variation_kept, ...
0013 run_all_objective_functions, kernel, save_data, load_data, ...
0014 save_bumps, draw_warp_curve, overlap_scores, show_target, ...
0015 format, filter, filter_level, model_score_type, gen_iters, ...
0016 spec_iters, draw_curve_by_images);
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
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092 if (nargin == 0),
0093 disp(' ');
0094 disp('Argument(s) ommited. Using defaults instead.');
0095 disp(' ');
0096 spline_type = 'multi_point';
0097
0098
0099
0100 placement_type = 'random';
0101
0102 objective_function = 'model_opt_together';
0103
0104 apply_intensity_offset = 1;
0105
0106
0107
0108 save_movie = 0;
0109
0110
0111
0112 do_plot = 0;
0113
0114
0115
0116
0117 movie_type = 1;
0118
0119
0120
0121 movie_name = 'undefined';
0122 format = 'png';
0123 gen_iters = 25;
0124
0125
0126 spec_iters = 25;
0127
0128 progress_bar = 1;
0129
0130
0131
0132
0133
0134 model_score_tyype = 'Deafault';
0135 user_menu = 0;
0136 number_of_bins=50;
0137
0138
0139 produce_statistics = 0;
0140
0141 see_model_before_each_iteration = 0;
0142
0143
0144 show_pixels = 0;
0145
0146
0147 show_score_vs_iteration = 0;
0148 show_model_after_optimisation = 0;
0149 show_specificity_statistics = 0;
0150
0151 verbose_score = 0;
0152
0153 average_smooth_enabled = 0;
0154 gaussian_smooth_enabled = 0;
0155 window = 1;
0156
0157 plot_before_and_after = 0;
0158
0159 bump_width = 0.2;
0160 bump_width_variation = 0.5;
0161 bump_height = 0.2;
0162 bump_height_variation = 0.3;
0163 bump_position_freedom = 0.9;
0164 initial_diminish_factor = 2;
0165 smoothness_factor = 17;
0166
0167
0168 model_evaluation_method = 1;
0169
0170
0171
0172 show_score_using_model = 0;
0173 handle = 'Default';
0174
0175 n_modes = 20;
0176 variation_kept = 0.99;
0177
0178
0179 shape_weight = 0.06;
0180 weighting_normalisation_method = 'edge';
0181 run_all_objective_functions = 0;
0182
0183 called_from_gui = 0;
0184
0185 kernel = 'Exponential';
0186 save_data = 0;
0187 load_data = 0;
0188 save_bumps = 0;
0189 draw_warp_curve = 0;
0190 draw_curve_by_images = 0;
0191 overlap_scores = 0;
0192 show_target = 0;
0193
0194 else
0195 called_from_gui = 1;
0196
0197
0198 end
0199
0200
0201
0202
0203
0204
0205 n_images = 2;
0206
0207 n_iterations = 2;
0208
0209 n_sets = 1;
0210
0211 image_width = 50;
0212
0213 n_points = 5;
0214
0215
0216
0217
0218
0219
0220
0221 warning off;
0222
0223 error_found = 0;
0224
0225 status = [' '];
0226
0227 if (run_all_objective_functions == 1),
0228 colour = 'r';
0229
0230 style = ':';
0231
0232 progress_bar = 2;
0233 end
0234
0235
0236
0237
0238 verbose = 'off';
0239
0240 if strcmp(movie_name, 'undefined'),
0241 movie_name = ['movie_', spline_type, '_', placement_type, '_', objective_function,'_width', num2str(image_width), '_images', num2str(n_images), '_iterations', num2str(n_iterations), '.avi'];
0242
0243
0244 end
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269 frame_counter = 0;
0270
0271
0272 if (progress_bar == 0),
0273 progress_indicator_type = 'Hierarchical Text';
0274 elseif (progress_bar == 1),
0275 progress_indicator_type = 'Progress Bar';
0276 elseif (progress_bar == 2),
0277 progress_indicator_type = 'Quiet';
0278 elseif (progress_bar == 3),
0279 progress_indicator_type = 'Console Progress Bar';
0280 else
0281 error('Callback value for progress indicator is not recognised');
0282 end
0283
0284
0285
0286
0287
0288
0289 if (user_menu == 1),
0290 [n_sets, n_iterations, n_images, image_width] = get_parameters_from_user('Default');
0291 end
0292
0293 tic;
0294
0295 for this_set = 1:n_sets
0296
0297
0298
0299 tic;
0300
0301
0302
0303
0304
0305
0306 if (strcmp(progress_indicator_type,'Hierarchical Text')),
0307 disp(['calculating set ', num2str(this_set), ' out of ', num2str(n_sets), ' sets...']);
0308 elseif (strcmp(progress_indicator_type,'Progress Bar')),
0309 gui_active(1);
0310 if (strcmp(getenv('OS'), 'Linux')),
0311 h = progressbar( [], 0, 'Preparing for registration', [['Registration Progress on '], [get_host]]);
0312 else
0313 h = progressbar( [], 0, 'Preparing for registration', 'Registration Progress');
0314 end
0315 end
0316
0317
0318 if (strcmp(progress_indicator_type,'Progress Bar')),
0319 h = progressbar( h, 0, 'Fetching Data');
0320 end
0321
0322
0323 if (load_data == 0),
0324 [imagelist, images, points] = make_1d_bump(n_images, image_width...
0325 , bump_width, bump_width_variation, bump_height, bump_height_variation...
0326 , bump_position_freedom, initial_diminish_factor, smoothness_factor...
0327 , save_bumps, format);
0328
0329 if (called_from_gui == 1 & save_bumps == 1),
0330 status = [[status];['(**) Images saved '];[' ']];
0331 end
0332 else
0333 output = open([[handle],['.mat']]);
0334 points = output.points;
0335 images = output.images;
0336
0337 end
0338
0339 if (save_data == 1)
0340 save([[handle],['.mat']], 'images','points');
0341 if (called_from_gui == 1),
0342 status = [[status];['(**) Data saved '];[' ']];
0343 end
0344 end
0345
0346 figure;
0347 [X,Y] = meshgrid(n_images, -image_width/2:1:image_width/2-1);
0348 Z = zeros(n_images, image_width);
0349 size(X)
0350 size(Y)
0351 size(Z)
0352 size(images)
0353 for i = 1:n_images,
0354 Z(:,i) = images(:,i);
0355 end
0356 mesh(X,Y,Z);
0357 axis([-30 30 -30 30 -1 1]);
0358
0359
0360
0361 if (strcmp(progress_indicator_type,'Progress Bar')),
0362 h = progressbar( h, 0, 'Pre-processing Data');
0363 end
0364
0365 if (average_smooth_enabled),
0366 images = average_smooth(images, window);
0367 end
0368
0369 if (gaussian_smooth_enabled),
0370 images = gaussian_smooth(images, window);
0371 end
0372
0373
0374 if (apply_intensity_offset),
0375 vertical_pane_location = 3;
0376
0377 else
0378 vertical_pane_location = 2;
0379
0380 end
0381
0382 points = -1 + 2 * (points - 1) / (image_width - 1);
0383
0384
0385
0386 ref_points_vec = points(:,1);
0387 ref_image_vec = images(:,1);
0388
0389
0390
0391
0392
0393
0394
0395 if (draw_warp_curve == 1),
0396 overlap_curve_fig = figure('Name','Overlapping Warp Curves');
0397 end
0398
0399 if (show_pixels == 1),
0400 pixels_figure = figure('Name','Pixel Representation');
0401 end
0402
0403
0404
0405 if (draw_curve_by_images == 1),
0406 curve_subplot_fig = figure('Name',[['Warp Curves for all data - objective function: '],[objective_function]]);
0407 curves = figure(curve_subplot_fig);
0408 for i=1:n_images,
0409 subplot(n_images, n_iterations + 1, i * (n_iterations + 1) - n_iterations);
0410 hold on;
0411 axis off;
0412 plot(points(:,i));
0413 axis([-1 image_width -1 1]);
0414 hold off;
0415 end
0416 end
0417
0418
0419
0420
0421
0422
0423
0424
0425
0426
0427 if (plot_before_and_after),
0428 for i=1:n_images,
0429 images_before_offset(:,i) = images(:,i);
0430 end
0431 end
0432 if (do_plot),
0433 subplot_fig = figure('Name',[[handle],[': Left: Original images ; Right: Images subjected to warping']]);
0434 H=figure(subplot_fig);
0435 for i=1:n_images,
0436 subplot(n_images, vertical_pane_location, (vertical_pane_location * i) - vertical_pane_location + 1);
0437 hold on;
0438 plot(images(:,i));
0439
0440 axis([0 image_width 0 1]);
0441 grid on;
0442 hold off;
0443 end
0444 else
0445 subplot_fig = 0;
0446
0447 end
0448
0449 if (apply_intensity_offset),
0450 for index = 1:n_images,
0451 peak (index) = max(images(:,index));
0452 end
0453 peak_reference = max (peak);
0454 for index = 1:n_images,
0455 peak_difference = peak_reference - max(images(:,index));
0456 images(:,index) = images(:,index) + peak_difference;
0457 if (do_plot),
0458 subplot(n_images, vertical_pane_location, (vertical_pane_location * index) - vertical_pane_location + 2);
0459 hold on;
0460 plot(images(:,index));
0461
0462 axis([0 image_width 0 1]);
0463 grid on;
0464 hold off;
0465 end
0466 end
0467 end
0468
0469
0470 still_to_go = 1;
0471
0472
0473
0474
0475 while (still_to_go == 1),
0476
0477 if (run_all_objective_functions == 0)
0478 still_to_go = 0;
0479
0480 else
0481
0482 if strcmp(objective_function, 'all'),
0483
0484 objective_function = 'model_opt_together';
0485 elseif strcmp(objective_function, 'model_opt_together'),
0486 objective_function = 'model_opt_separate';
0487 elseif strcmp(objective_function, 'model_opt_separate'),
0488 objective_function = 'msd_opt_together';
0489 elseif strcmp(objective_function, 'msd_opt_together'),
0490 objective_function = 'msd_opt_separate';
0491 elseif strcmp(objective_function, 'msd_opt_separate'),
0492 objective_function = 'mi_opt_together';
0493 elseif strcmp(objective_function, 'mi_opt_together'),
0494 objective_function = 'mi_opt_separate';
0495 elseif strcmp(objective_function, 'mi_opt_separate'),
0496 objective_function = 'nmi_opt_together';
0497 elseif strcmp(objective_function, 'nmi_opt_together'),
0498 objective_function = 'nmi_opt_separate';
0499 elseif strcmp(objective_function, 'nmi_opt_separate'),
0500 objective_function = 'void';
0501 still_to_go = 0;
0502
0503
0504 else
0505 error('Problem with <Run All Objective Functions> option');
0506 end
0507 end
0508
0509 warped_images = images;
0510 warped_points = points;
0511
0512
0513
0514
0515
0516
0517
0518
0519
0520
0521
0522
0523
0524
0525
0526
0527
0528
0529 if ((strcmp(progress_indicator_type,'Console Progress Bar')) | (strcmp(progress_indicator_type,'Progress Bar')))
0530 progress_bar_position = 0;
0531 time_for_this_iteration = 10;
0532 total_images = n_images * n_iterations;
0533 step_size = 50 / total_images;
0534 end
0535
0536 for n = 1:n_iterations,
0537 if (strcmp(progress_indicator_type,'Hierarchical Text'))
0538
0539 disp([' +-Running iteration number ',num2str(n), ' out of ',num2str(n_iterations), ' iterations...']);
0540 end
0541
0542
0543
0544
0545 if (see_model_before_each_iteration),
0546 w_c_model = build_model(warped_images, warped_points, variation_kept,'Optimised warp', weighting_normalisation_method);
0547
0548 show_combined_model(w_c_model,ref_points_vec, 2, 2, [[handle],[': Combined model before iteration number ', num2str(n)]]);
0549
0550 end
0551 for i = 1:n_images,
0552
0553 if (strcmp(progress_indicator_type,'Hierarchical Text')),
0554 disp([' +-Warping image ',num2str(i),' out of ',num2str(n_images), ' images in total...']);
0555 end
0556
0557 this_step = ((n-1) * n_images) + i;
0558
0559 if (strcmp(progress_indicator_type,'Progress Bar')),
0560 tic;
0561 progress_bar_position = progress_bar_position + step_size;
0562 steps_remaining = (n_images * n_iterations) - this_step;
0563 minutes = floor(time_for_this_iteration * steps_remaining / 60);
0564 seconds = rem(floor(time_for_this_iteration * steps_remaining), 60);
0565 max_count = 50;
0566
0567 if (seconds > 9),
0568 h = progressbar( h, step_size/50,[' Estimated remaining time: ', num2str(minutes), ':', num2str(seconds)]);
0569 else
0570 h = progressbar( h, step_size/50,[' Estimated remaining time: ', num2str(minutes), ':0', num2str(seconds)]);
0571 end
0572 if ~gui_active,
0573 error_found = 1;
0574 break;
0575 end
0576
0577
0578 end
0579 if (strcmp(progress_indicator_type,'Console Progress Bar')),
0580
0581 tic;
0582 progress_bar_position = progress_bar_position + step_size;
0583 clc;
0584 disp(['|=================================================|']);
0585 progress_string='|';
0586 for counter = 1:floor(progress_bar_position),
0587 progress_string = [progress_string, '#'];
0588 end
0589 disp(progress_string);
0590 disp(['|================= ',num2str(floor(progress_bar_position * 2)),'% completed =================|']);
0591
0592 steps_remaining = (n_images * n_iterations) - this_step;
0593 minutes = floor(time_for_this_iteration * steps_remaining / 60);
0594 seconds = rem(floor(time_for_this_iteration * steps_remaining), 60);
0595 disp(' ');
0596 if (seconds > 9),
0597 disp([' Estimated remaining time: ', num2str(minutes), ':', num2str(seconds)]);
0598
0599 else
0600 disp([' Estimated remaining time: ', num2str(minutes), ':0', num2str(seconds)]);
0601 end
0602 end
0603 image_vec = warped_images(:,i);
0604 points_vec = warped_points(:,i);
0605
0606 if (show_pixels == 1),
0607 appended_vector=[];
0608 for current_image=1:n_images,
0609 appended_vector=[[appended_vector],[warped_images(:,current_image),[warped_images(:,current_image)]],[warped_images(:,current_image)]];
0610
0611 end
0612
0613
0614
0615
0616 G = figure(pixels_figure);
0617 hold on;
0618
0619 imshow(appended_vector',[0,1]);
0620
0621 if (movie_type == 0 & save_movie == 1),
0622 frame_counter = frame_counter + 1;
0623 M(frame_counter) = getframe(G);
0624 end
0625 hold off;
0626 end
0627
0628 if (movie_type == 1 & save_movie == 1 & do_plot == 1),
0629 frame_counter = frame_counter + 1;
0630 M(frame_counter) = getframe(H);
0631 end
0632
0633 if (strcmp(objective_function,'model_opt_together')),
0634 [param_list, warped_point, warped_image, score] = optimise_all_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,spline_type,placement_type,n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, model_evaluation_method, n_modes, weighting_normalisation_method, shape_weight, variation_kept);
0635 elseif(strcmp(objective_function,'void')),
0636 break;
0637 elseif(strcmp(objective_function,'model_opt_separate')),
0638 [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,spline_type, placement_type,n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, model_evaluation_method, n_modes, weighting_normalisation_method, shape_weight, variation_kept);
0639 elseif(strcmp(objective_function,'msd_opt_together')),
0640 [param_list, warped_point, warped_image, score] = optimise_all_warps_msd(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score);
0641 elseif(strcmp(objective_function,'msd_opt_separate')),
0642 [param_list, warped_point, warped_image, score] = optimise_warps_msd(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score);
0643 elseif(strcmp(objective_function,'mi_opt_together')),
0644 [param_list, warped_point, warped_image, score] = optimise_all_warps_mi(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, number_of_bins);
0645 elseif(strcmp(objective_function,'mi_opt_separate')),
0646 [param_list, warped_point, warped_image, score] = optimise_warps_mi(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, number_of_bins);
0647 elseif(strcmp(objective_function,'nmi_opt_together')),
0648 [param_list, warped_point, warped_image, score] = optimise_all_warps_nmi(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, number_of_bins);
0649 elseif(strcmp(objective_function,'nmi_opt_separate')),
0650 [param_list, warped_point, warped_image, score] = optimise_warps_nmi(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, number_of_bins);
0651 elseif(strcmp(objective_function,'mixed_msd_model')),
0652 if (((n / n_iterations < 2 / 10) & (n / n_iterations >= 1 / 10)) |...
0653 ((n / n_iterations < 4 / 10) & (n / n_iterations >= 3 / 10)) |...
0654 ((n / n_iterations < 6 / 10) & (n / n_iterations >= 5 / 10)) |...
0655 ((n / n_iterations < 8 / 10) & (n / n_iterations >= 7 / 10)) |...
0656 ((n / n_iterations < 10 / 10) & (n / n_iterations >= 9 / 10))),
0657 [param_list, warped_point, warped_image, score] = optimise_all_warps_msd(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score);
0658 else
0659 [param_list, warped_point, warped_image, score] = optimise_all_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,spline_type,placement_type,n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, model_evaluation_method, n_modes, weighting_normalisation_method, shape_weight, variation_kept);
0660 end
0661 elseif(strcmp(objective_function,'model_post_msd')),
0662 if (n / n_iterations < 1 / 2),
0663
0664 [param_list, warped_point, warped_image, score] = optimise_all_warps_msd(ref_image_vec, ref_points_vec, image_vec, points_vec, spline_type, placement_type, n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score);
0665 else
0666
0667 [param_list, warped_point, warped_image, score] = optimise_all_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,spline_type,placement_type,n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, model_evaluation_method, n_modes, weighting_normalisation_method, shape_weight, variation_kept);
0668 end
0669 elseif(strcmp(objective_function,'tfc_eccv')),
0670
0671 pdf_evalution_method = 'Default';
0672 [param_list, warped_point, warped_image, score] = optimise_groupwise([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,spline_type,placement_type,n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, model_evaluation_method, n_modes, weighting_normalisation_method, shape_weight, variation_kept, pdf_evalution_method, kernel);
0673 elseif(strcmp(objective_function,'wavelet_complexity')),
0674
0675 wavelet_evalution_method = 'Default';
0676 [param_list, warped_point, warped_image, score] = optimise_wavelet([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,spline_type,placement_type,n_points, verbose, do_plot, subplot_fig, i * vertical_pane_location, vertical_pane_location, image_width, n_images, verbose_score, model_evaluation_method, n_modes, weighting_normalisation_method, shape_weight, variation_kept, wavelet_evalution_method, filter, filter_level);
0677
0678 else
0679 error(['Unknown objective function: ', objective_function]);
0680 end
0681
0682 if (draw_warp_curve == 1),
0683 figure(overlap_curve_fig);
0684 hold on;
0685 plot(warped_points);
0686 hold off;
0687 end
0688
0689 if (draw_curve_by_images == 1),
0690 figure(curves);
0691 subplot(n_images, n_iterations + 1, i * (n_iterations + 1) - (n_iterations - n));
0692 hold on;
0693 axis off;
0694 plot(warped_points(:,i));
0695 axis([-1 image_width -1 1]);
0696 hold off;
0697 end
0698
0699 warped_images(:,i) = warped_image;
0700 warped_points(:,i) = warped_point;
0701
0702
0703
0704
0705 if (show_score_using_model == 1),
0706
0707 c_model = build_model(warped_images, warped_points, variation_kept, '', weighting_normalisation_method, shape_weight);
0708
0709 if (strcmp(model_score_type, 'Default')),
0710 score = measure_model(c_model.variances, n_modes, model_evaluation_method, c_model);
0711 elseif (strcmp(model_score_type, 'Specificity')),
0712 score = find_specificity(c_model, images, spec_iters, ref_points_vec);
0713 elseif (strcmp(model_score_type, 'Generalisability')),
0714 score = find_generalisability(c_model, gen_iters);
0715 elseif (strcmp(model_score_type, 'Mean MSD')),
0716 score = measure_model_msd(warped_images);
0717 elseif (strcmp(model_score_type, 'All')),
0718
0719
0720 all_scores = [[find_specificity(c_model, images, spec_iters, ref_points_vec)], [find_generalisability(c_model, gen_iters)], [measure_model_msd(warped_images)]];
0721
0722
0723 else
0724 error(['Wrong scoring method (', [model_score_type], ') passed. Internal error.']);
0725 end
0726
0727 end
0728
0729
0730 if(n == n_iterations),
0731 final_score(i, this_set) = score;
0732
0733 end
0734
0735 score_for_iteration(i,n) = score;
0736
0737
0738 if (strcmp(model_score_type, 'All')),
0739 all_scores_for_iteration(i,n,1) = all_scores(1);
0740 all_scores_for_iteration(i,n,2) = all_scores(2);
0741 all_scores_for_iteration(i,n,3) = all_scores(3);
0742 end
0743 if ((strcmp(progress_indicator_type,'Progress Bar')) | (strcmp(progress_indicator_type,'Console Progress Bar'))),
0744 times(this_step) = toc;
0745 time_for_this_iteration = mean (times);
0746 end
0747 end
0748 end
0749 if (strcmp(progress_indicator_type,'Progress Bar')),
0750 h = progressbar( h, 0, 'Finalising');
0751 end
0752 if (show_score_vs_iteration),
0753
0754
0755
0756
0757
0758
0759
0760
0761
0762
0763
0764
0765
0766
0767
0768
0769
0770
0771
0772
0773
0774
0775
0776
0777
0778 if (overlap_scores == 0),
0779 figure('Name', [[handle],[': Score versus image warping step - objective function: '],[objective_function]]);
0780
0781 else
0782
0783 figure(101);
0784 end
0785
0786 hold on;
0787
0788 if (strcmp(model_score_type, 'All')),
0789 title('Proportional score versus image warping step');
0790 xlabel('Warping Step');
0791 ylabel('% Change');
0792 position_counter = 0;
0793 for i=1:n_iterations,
0794 for j=1:n_images,
0795 position_counter = position_counter + 1;
0796 all_warp_step_score_vector(position_counter,1) = all_scores_for_iteration(j,i,1);
0797 all_warp_step_score_vector(position_counter,2) = all_scores_for_iteration(j,i,2);
0798 all_warp_step_score_vector(position_counter,3) = all_scores_for_iteration(j,i,3);
0799 end
0800 end
0801 all_warp_step_percent_vector(1,1) = 0;
0802
0803 all_warp_step_percent_vector(2,1) = 0;
0804 all_warp_step_percent_vector(3,1) = 0;
0805
0806 for i = 2:n_iterations * n_images,
0807 all_warp_step_percent_vector(1,i) = (all_warp_step_score_vector(i,1) - all_warp_step_score_vector(i-1,1)) / (all_warp_step_score_vector(i-1,1) + 0.001) * 100;
0808 all_warp_step_percent_vector(2,i) = (all_warp_step_score_vector(i,2) - all_warp_step_score_vector(i-1,2)) / (all_warp_step_score_vector(i-1,2) + 0.001) * 100;
0809 all_warp_step_percent_vector(3,i) = (all_warp_step_score_vector(i,3) - all_warp_step_score_vector(i-1,3)) / (all_warp_step_score_vector(i-1,3) + 0.001) * 100;
0810 end
0811 else
0812 title('Score versus image warping step');
0813 xlabel('Warping Step');
0814 ylabel('Score');
0815 position_counter = 0;
0816 for i=1:n_iterations,
0817 for j=1:n_images,
0818 position_counter = position_counter + 1;
0819 warp_step_score_vector(position_counter) = score_for_iteration(j,i);
0820 end
0821 end
0822 end
0823 if (run_all_objective_functions == 1),
0824 if strcmp(colour,'r'),
0825 colour = 'g';
0826 elseif strcmp(colour,'g')
0827 colour = 'b';
0828 else
0829 colour = 'r';
0830 end
0831
0832 if strcmp(style,':'),
0833 style = '-';
0834 elseif strcmp(style,'-')
0835 style = '--';
0836 elseif strcmp(style,'--')
0837 style = '-.';
0838 else
0839 style = ':';
0840 end
0841 plot(warp_step_score_vector,[[colour],[style]]);
0842 legend('Sequential MSD','Joint MSD','Sequential Model-based','Joint Model-based','Squential MI',...
0843 'Joint MI', 'Sequential NMI', 'Joint NMI','Void');
0844 else
0845
0846 if (strcmp(model_score_type, 'All')),
0847 plot (all_warp_step_percent_vector(1,:), 'r');
0848 plot (all_warp_step_percent_vector(2,:), 'g');
0849 plot (all_warp_step_percent_vector(3,:), 'b');
0850 legend('Specificity', 'Generalisability', 'Mean MSD');
0851 else
0852 plot (warp_step_score_vector);
0853 end
0854 if (show_target == 1),
0855 Epsilon = 0.0001;
0856 plot (repmat([log(Epsilon.^n_modes)], 1,n_iterations * n_images),'--');
0857 legend('Current Evaluation','Log eigenvalues of perfectly registered images');
0858 end
0859 end
0860 hold off;
0861 end
0862
0863 w_c_model = build_model(warped_images, warped_points, variation_kept, 'Optimised warp', weighting_normalisation_method, shape_weight);
0864
0865 w_intensity_total_vars = w_c_model.intensity_model.total_var;
0866 w_shape_total_vars = w_c_model.shape_model.total_var;
0867
0868 model_score(this_set) = measure_model(w_c_model.variances, n_modes, model_evaluation_method, w_c_model);
0869 msd_score(this_set) = measure_model_msd(warped_images);
0870 shape_modes(this_set) = w_c_model.n_shape_modes;
0871 intensity_modes(this_set) = size(w_c_model.intensity_model.pcs,2);
0872 shape_variance(this_set) = sum(w_c_model.shape_model.variances);
0873 intensity_variance(this_set) = sum(w_c_model.intensity_model.variances);
0874
0875
0876 if (show_model_after_optimisation),
0877 show_combined_model(w_c_model,ref_points_vec, 2, 2, [[handle],[': Final combined model built from optimised warps - objective function: '],[objective_function]]);
0878 end
0879
0880 if (show_specificity_statistics),
0881 [w_c_model.mean_specificity, w_c_model.std_specificity] = find_specificity(w_c_model, images, spec_iters, ref_points_vec);
0882 disp(' ');
0883 disp([['Objective function: '], [objective_function]]);
0884 disp(['Mean of specificity: ', num2str(w_c_model.mean_specificity)]);
0885 disp(['Standard deviation of specificity: ', num2str(w_c_model.std_specificity)]);
0886 end
0887
0888
0889
0890
0891
0892
0893
0894
0895
0896
0897
0898
0899
0900
0901
0902
0903
0904
0905
0906
0907
0908
0909
0910 if (plot_before_and_after),
0911 subplot_fig = figure('Name', [[handle],[': Left: Before registration; Right: After Registration - Objective function: '], [objective_function]]);
0912 H=figure(subplot_fig);
0913 for i=1:n_images,
0914 subplot(n_images, vertical_pane_location, (vertical_pane_location * i) - vertical_pane_location + 1);
0915 hold on;
0916 plot(images_before_offset(:,i));
0917
0918 axis([0 image_width 0 1]);
0919 grid on;
0920 hold off;
0921 end
0922 if (apply_intensity_offset),
0923 for index = 1:n_images,
0924 peak (index) = max(images(:,index));
0925 end
0926 peak_reference = max (peak);
0927 for index = 1:n_images,
0928 peak_difference = peak_reference - max(images(:,index));
0929 images(:,index) = images(:,index) + peak_difference;
0930 subplot(n_images, vertical_pane_location, (vertical_pane_location * index) - vertical_pane_location + 2);
0931 hold on;
0932 plot(images(:,index));
0933
0934 axis([0 image_width 0 1]);
0935 grid on;
0936 hold off;
0937 end
0938 end
0939
0940
0941 for i=1:n_images,
0942 subplot(n_images, vertical_pane_location, i * vertical_pane_location);
0943 hold on;
0944 plot(warped_images(:,i));
0945
0946 axis([0 image_width 0 1]);
0947 grid on;
0948 hold off;
0949 end
0950 else
0951 subplot_fig = 0;
0952 end
0953
0954
0955 end
0956
0957 t = toc;
0958
0959 if (strcmp(progress_indicator_type,'Hierarchical Text')),
0960 disp(['Time for set ',num2str(this_set),': ',num2str(t)]);
0961 end
0962 time(this_set) = t;
0963
0964 end
0965
0966 if (strcmp(progress_indicator_type,'Progress Bar')),
0967 progressbar( h,-1 );
0968
0969 end
0970
0971 if (produce_statistics == 1),
0972 disp(' ');
0973 disp(['======================================================']);
0974 disp(['================= SET STATISTICS =====================']);
0975 disp(['| Objective function: ', objective_function]);
0976 disp(['| Mean of match score: ', num2str(mean(final_score(:)))]);
0977 disp(['| Standard deviation of match score: ', num2str(std(final_score(:)))]);
0978 disp(['| Mean of model score: ', num2str(mean(model_score(:)))]);
0979 disp(['| Standard deviation of model score: ', num2str(std(model_score(:)))]);
0980 disp(['| Mean of msd score: ', num2str(mean(msd_score(:)))]);
0981 disp(['| Standard deviation of msd score: ', num2str(std(msd_score(:)))]);
0982 disp(['| Mean of shape modes: ', num2str(mean(shape_modes(:)))]);
0983 disp(['| Standard deviation of shape modes: ', num2str(std(shape_modes(:)))]);
0984 disp(['| Mean of intensity modes: ', num2str(mean(intensity_modes(:)))]);
0985 disp(['| Standard deviation of intensity modes: ', num2str(std(intensity_modes(:)))]);
0986 disp(['| Mean of shape variance: ', num2str(mean(shape_variance(:)))]);
0987 disp(['| Standard deviation of shape variance: ', num2str(std(shape_variance(:)))]);
0988 disp(['| Mean of intensity variance: ', num2str(mean(intensity_variance(:)))]);
0989 disp(['| Standard deviation of intensity variance: ', num2str(std(intensity_variance(:)))]);
0990 disp(['| Mean time: ', num2str(mean(time(:)))]);
0991 disp(['| Standard deviation of time: ', num2str(std(time(:)))]);
0992 t = toc;
0993
0994 disp(['| Total time: ',num2str(t)]);
0995
0996 disp(['======================================================']);
0997 end
0998
0999
1000 if (save_movie == 1)
1001 movie(M);
1002 movie2avi(M,movie_name);
1003 disp(' ');
1004 disp([movie_name, ' saved']);
1005
1006 if (called_from_gui == 1),
1007 status = [[status];['(**) Video saved '];[' ']];
1008 end
1009 end
1010
1011 if (error_found == 0),
1012
1013 if (called_from_gui == 1),
1014 status = [[status];['Registration Completed'];
1015 [' '];
1016 ['Status: OK ']];
1017
1018 else
1019 status = 'Status: OK';
1020
1021 end
1022 elseif (error_found == 1),
1023 if (called_from_gui == 1),
1024 status = [[status];['Registration Completed'];
1025 [' '];
1026 ['Status: Error '];
1027 [' '];
1028 ['Operation Aborted ']];
1029
1030 else
1031 status = 'Status: Operation Aborted';
1032
1033 end
1034 else
1035 if (called_from_gui == 1),
1036 status = [[status];['Registration Completed'];
1037 [' '];
1038 ['Status: Error '];
1039 [' '];
1040 ['Exit code unknown ']];
1041
1042 else
1043 status = 'Status: Error';
1044
1045 end
1046 end
1047
1048
1049