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