-
Notifications
You must be signed in to change notification settings - Fork 6
/
homo_eval.m
75 lines (60 loc) · 2.76 KB
/
homo_eval.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
clear
close all
%-------------------------------------------------------------------------%
model_type = 'homography';
%-------------------------------------------------------------------------%
data_path = 'data/AdelaideRMF/H';
data_files = dir(data_path);
data_files(1:2) = [];
num_repetitions = 100;
seg_errors = zeros(length(data_files), num_repetitions);
for f=1:length(data_files)
fprintf('Processing data %s \n', data_files(f).name);
file_name = strcat(data_files(f).folder, '/', data_files(f).name);
pack = load(file_name);
%--- Prepare data --------------------------------------------------------%
xy = pack.data;
I1 = pack.img1;
I2 = pack.img2;
GT = pack.label;
%---Normalize data--------------------------------------------------------%
[dat_img_1, T1] = normalise2dpts(xy(1:3,:));
[dat_img_2, T2] = normalise2dpts(xy(4:6,:));
data = [dat_img_1 ; dat_img_2];
%-------------------------------------------------------------------------%
%----------Set parameters-------------------------------------------------%
param.sig = 0.05; % Standard deviation of noise
param.smoothness = 0.1; % Smoothness cost
param.min_inliers = 10; % Minimum number of inlier per structure
param.rcm_sampling = 1; % Used RCM sampling method
param.sa = 0.99; % Simulated Annealing Schedule
param.max_iteration = 5000; % Max number of iterations
param.min_iteration = 500; % Min number of iterations
param.K = 10; % Patch size to update the weight
%-------------------------------------------------------------------------%
%---Robust model fitting--------------------------------------------------%
for i=1:num_repetitions
[estimated_pars, segmentation, ~] = rcmsa_model_fitting(data, xy, model_type, param);
% Evaluation
seg_errors(f, i) = segmentation_error(segmentation, GT);
end
fprintf('Median error = %f \n', median(seg_errors(f,:)));
%-------------------------------------------------------------------------%
%--Display segmentation result--------------------------------------------%
display = 0;
if display == 1
figure(f);
imshow(I1);hold on
gscatter(xy(1,:), xy(2,:), segmentation, [], [], 20);
title('The first label in red is outlier label');
end
drawnow;
%-------------------------------------------------------------------------%
end
mean_err = mean(seg_errors, 2);
median_err = median(seg_errors, 2);
fprintf('\n');
fprintf('%s \t %s \t %s \n', pad('Image', 50), 'Mean Error', 'Median Error');
for f=1:length(data_files)
fprintf('%s \t %f \t %f \n', pad(data_files(f).name, 50), mean_err(f), median_err(f));
end