-
Notifications
You must be signed in to change notification settings - Fork 0
/
anti_noise_exp.m
115 lines (100 loc) · 2.99 KB
/
anti_noise_exp.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
%% The following code was written in MATLAB R2020a.
clear; close all;
addpath(genpath(pwd));
%%
% read the image and blur the image with a gaussian function with sigma = 5
im = rgb2gray(mat2gray(imread('data/hk_sub_image.png')));
step = 7;
sigma = 5;
alpha = step / sigma;
kernel = sqrt(gausswin(2 * step + 1, alpha) * gausswin(2 * step + 1, alpha)');
kernel = kernel / sum(kernel(:));
im = imfilter(im, kernel);
clear alpha kernel sigma;
%%
% initial the parameters
% the standard deviation of the noise ranges from 0 to 0.2
num = 10;
noise = linspace(0, 0.2, num);
e = zeros(num, 6, 6 * 6 * 5);
loc = zeros([2, 6]);
[decimalx, decimaly] = meshgrid(1:step - 1);
decimal = [decimalx(:), decimaly(:)];
tic;
for n = 1:num
count = 1;
for integer = [0, 5, 10, 15, 20]
for k = 1:length(decimal)
% generate the image pair with specific displacments
[im1, im2] = img_pair_gen(im, step, integer, decimal(k, :));
% generate the true displacements
sft = (integer + decimal(k, :)' / step);
% add zero mean gaussian noise to the two images
im1_ = im1 + randn(size(im1)) * noise(n);
im2_ = im2 + randn(size(im2)) * noise(n);
% estimating the displacements
% IDFT-US
loc(:, 1) = IDFT_US(im1_, im2_, 20);
% SVD-RANSAC
loc(:, 2) = SVD_RANSAC(im1_, im2_);
tmp = CSM_itr(im1_, im2_, 3);
% Stone
loc(:, 3) = tmp(1, :);
% CSM(3)
loc(:, 4) = tmp(3, :);
tmp = ANCPS_itr(im1_, im2_, 3);
% ANCPS(1)
loc(:, 5) = tmp(1, :);
% ANCPS(3)
loc(:, 6) = tmp(3, :);
% record the error
for i = 1:6
e(n, i, count) = norm(loc(:, i) - sft);
end
count = count + 1;
end
end
disp([num2str(n / num * 100), '%']);
end
toc;
%%
% plot the results
name_list = {'IDFT-US' 'SVD-RANSAC' 'Stone' 'CSM(3)' 'ANCPS(1)', 'ANCPS(3)'};
color_list = lines;
color_list = color_list([1, 4:6, 2, 3], :);
marker_list = 'osd^ph';
set(0, 'DefaultAxesFontSize', 16);
set(0, 'DefaultLineLineWidth', 2);
e_mean = mean(e, 3);
e_max = max(e, [], 3);
e_std = std(e, [], 3);
figure, hold on;
for i = 1:6
plot(noise, e_mean(:, i), [marker_list(i), '-'], 'MarkerSize', 8, 'Color', color_list(i, :));
end
axis square;
legend(name_list, 'Location', 'northwest', 'FontSize', 16);
box on;
grid on;
xlabel('\sigma_n');
ylabel('mean error');
figure, hold on;
for i = 1:6
plot(noise, e_max(:, i), [marker_list(i), '-'], 'MarkerSize', 8, 'Color', color_list(i, :));
end
axis square;
legend(name_list, 'Location', 'northwest', 'FontSize', 16);
box on;
grid on;
xlabel('\sigma_n');
ylabel('max error');
figure, hold on;
for i = 1:6
plot(noise, e_std(:, i), [marker_list(i), '-'], 'MarkerSize', 8, 'Color', color_list(i, :));
end
axis square;
legend(name_list, 'Location', 'northwest', 'FontSize', 16);
box on;
grid on;
xlabel('\sigma_n');
ylabel('std error');