-
Notifications
You must be signed in to change notification settings - Fork 3
/
demo_nonrigid.m
236 lines (188 loc) · 5.35 KB
/
demo_nonrigid.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
%% non-rigid deformation example
data_name = 5;%1=beijing;2=whale;3=chinese;4=cpd_fish;5=fish_2d;
X0 = load_testdata(data_name);
LX0 = length(X0(:,1));
[X0,X_bound] = normalize_point(X0,1);
sample_rate = 0.7;
samples = randperm(LX0);
LX_sample = round(sample_rate*LX0);
samples = samples(1:LX_sample);
X = X0(samples,:);
sigma = 2;
GX = nonrigid_ker(X,sigma,'rbf');
theta = 0.1*rand(1)*pi;
R = [cos(theta),sin(theta);
-sin(theta),cos(theta)];
W = 0.5*randn(length(X(:,1)),2);
t = 1*rand(1,2) + 0.5;
%t=[0,0];
scale = 1;
opt_non.noise = 1;
opt_non.noise_sigma = 0.0;
opt_non.noise_type = 'uniform';%'guassian'
opt_non.outlier = 50;
opt_non.out_sigma = 0.5;
opt_non.outlier_type = 'gaussian';%'uniform1''guassian''guassian1'
Y = scale*nonrigid_kernel_trans(X,W,GX,R,opt_non);
LY = length(Y(:,1));
Y = Y - repmat(mean(Y),LY,1) + repmat(t,LY,1);
opt_non.outlier = 50;
X = rigid_affine_transform2D(X,eye(2,2),[0,0],1,opt_non);
figure,plot(X(1:LX_sample,1),X(1:LX_sample,2),'r.',X(LX_sample+1:end,1),X(LX_sample+1:end,2),'g.','markersize',20);hold on;
plot(Y(:,1),Y(:,2),'g.',Y(1:LX_sample,1),Y(1:LX_sample,2),'b.','markersize',20);axis equal
order = randperm(LX_sample);
%order = 1:LX_sample;
X_inl = X(1:LX_sample,:);
X(1:LX_sample,:) = X_inl(order,:);
gt = zeros(LX_sample,LX_sample);
for i = 1:LX_sample
gt(i,order(i)) = 1;
end
asgT.X = gt;
LX = length(X(:,1));
gt_all = zeros(LX,LY);
for i = 1:LX_sample
gt_all(i,order(i)) = 1;
end
%% ZAR and ZACR
nF = LX_sample;
% match_rate = 0.5;
%nF = round(match_rate*LX)
% nF = nF_by_kmeans(X,Y,0,0)
GT = [1:length(order);order]';
opt_gm = set_option('w/o',nF,GT);
% opt_gm = set_option('w',nF,GT);%for ZACR
opt_gm.unary = 10;
opt_gm.remove_time = 5;
opt_gm.output = 0;
opt_reg.display = 1;
opt_reg.write = 0;
opt_reg.reg_maxiter = 30;
opt_reg.rota = 0;
opt_reg.reg_normalize = 1;
opt_reg.nonrigid_sig = 2;
opt_reg.unary_terms = [zeros(1,3),ones(1,50)];
opt_reg.lambda = 0.1;
opt_reg.type = 'nonrigid';
tic;
para = ZAC_nonrigid_2d(X,Y,opt_reg,opt_gm);
% para = ZAC_nonrigid_2d_r(X,Y,opt_reg,opt_gm);%for ZACR
toc;
% X_trans = para.sy0*para.X_new + repmat(para.uy,LX,1);
% X_tmp = para.sx0*para.X_tmp + repmat(para.ux,LX,1);
% Y_tmp = para.sy0*para.Y_tmp + repmat(para.uy,LY,1);
figure,plot(1:length(para.reg_Err),para.reg_Err,'r.-');hold on;
plot(1:length(para.reg_Diff),para.reg_Diff,'b.-');
YLIMmax = max(max(para.reg_Err),max(para.reg_Diff));
set(gca,'YLim',[0,YLIMmax+0.05]);
%% majiayi tip
opt.outliers = 1-LX_sample/LX;
tic;
[Transform1, C] = GLS_ma(X,Y,100,1,1);
toc;
reg_err_gls = measurement_XY(Transform1.Y,Y,Y,opt_gm.GT);
%% CPD
opt.method='nonrigid';
opt.corresp = 1; % compute correspondence vector at the end of registration (not being estimated by default)
opt.outliers = 1-LX_sample/LX;
opt.viz = 1;
opt.inl_num = LX_sample;
[Transform,C_cpd]=cpd_register(Y,X,opt);
% figure,cpd_plot_iter(XT, X); title('Before');
% figure,cpd_plot_iter(Transform.Y,XT); title('After');
figure,plot(Transform.Y(:,1),Transform.Y(:,2),'bo',Y(:,1),Y(:,2),'r.');
reg_err_cpd = measurement_XY(Transform.Y,Y,Y,opt_gm.GT)
%% GAGM
opt_gm.GT = GT;
opt_gm.full_or_del = 'del';
opt_gm.topk = nF;
opt_reg.reg_normalize = 1;
opt_reg.display = 1;
opt_reg.write = 0;
opt_reg.rota = 0;
opt_reg.reg_maxiter = 20;
opt_reg.unary_terms = [zeros(1,3),ones(1,50)];
opt_reg.nonrigid_sig = 2;
opt_reg.lambda = 1;
para_gagm = GAGM_nonrigid_2d(X,Y,opt_reg,opt_gm);
%% IFFPS
opt_gm.GT = GT;
opt_gm.full_or_del = 'del';
opt_gm.topk = nF;
opt_reg.reg_normalize = 1;
opt_reg.display = 1;
opt_reg.write = 0;
opt_reg.rota = 0;
opt_reg.reg_maxiter = 20;
opt_reg.unary_terms = [zeros(1,3),ones(1,50)];
opt_reg.nonrigid_sig = 2;
opt_reg.lambda = 1;
para_ipfps = IPFPS_nonrigid_2d(X,Y,opt_reg,opt_gm);
%% PSM
opt_gm.GT = GT;
opt_gm.full_or_del = 'del';
opt_gm.topk = nF;
opt_reg.reg_normalize = 1;
opt_reg.display = 1;
opt_reg.write = 0;
opt_reg.rota = 0;
opt_reg.reg_maxiter = 20;
opt_reg.unary_terms = [zeros(1,3),ones(1,50)];
opt_reg.nonrigid_sig = 2;
opt_reg.lambda = 1;
para_psm = PSM_nonrigid_2d(X,Y,opt_reg,opt_gm);
%% RRWM
opt_gm.GT = GT;
opt_gm.full_or_del = 'del';
opt_gm.topk = nF;
opt_reg.reg_normalize = 1;
opt_reg.display = 1;
opt_reg.write = 0;
opt_reg.rota = 0;
opt_reg.reg_maxiter = 20;
opt_reg.unary_terms = [zeros(1,3),ones(1,50)];
opt_reg.nonrigid_sig = 2;
opt_reg.lambda = 1;
para_rrwm = RRWM_nonrigid_2d(X,Y,opt_reg,opt_gm);
%% FGMD
opt_gm.GT = GT;
opt_gm.full_or_del = 'del';
opt_gm.topk = nF;
opt_reg.reg_normalize = 1;
opt_reg.display = 1;
opt_reg.write = 0;
opt_reg.rota = 0;
opt_reg.reg_maxiter = 20;
opt_reg.unary_terms = [zeros(1,3),ones(1,50)];
para_fgmd = FGMD_nonrigid_2d(X,Y,opt_reg,opt_gm);
%% MPM
opt_gm.GT = GT;
opt_gm.full_or_del = 'del';
opt_gm.topk = nF;
opt_reg.reg_normalize = 1;
opt_reg.display = 1;
opt_reg.write = 0;
opt_reg.rota = 0;
opt_reg.reg_maxiter = 20;
opt_reg.unary_terms = [zeros(1,3),ones(1,50)];
para_mpm = MPM_nonrigid_2d(X,Y,opt_reg,opt_gm);
%% FRGM
opt_gm = set_opt_FRGM(10,1,1);
opt_gm.GT = GT;
opt_gm.topk = LX_sample;
opt_gm.tol_cg = 1.0e-6;
opt_gm.Mexist = 1;
opt_gm.maxiter_nonvex = 100;
opt_gm.maxiter_convex = 100;
opt_gm.lam_nonvex = 1;
opt_gm.lam_convex = 1;
opt_gm.lam_sparse = 0;
opt_gm.geofunc = '1.21';
opt_gm.unary = 1;
opt_reg.reg_normalize = 1;
opt_reg.display = 1;
opt_reg.write = 0;
opt_reg.rota = 0;
opt_reg.reg_maxiter = 30;
opt_reg.unary_terms = [zeros(1,3),ones(1,50)];
para_frgm = FRGM_nonrigid_2d_fast(X,Y,opt_reg,opt_gm);