summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic/affine/compute_AD.m
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/affine/compute_AD.m')
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/compute_AD.m90
1 files changed, 90 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/compute_AD.m b/SD-VBS/common/toolbox/toolbox_basic/affine/compute_AD.m
new file mode 100755
index 0000000..a39acd6
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/compute_AD.m
@@ -0,0 +1,90 @@
1function [A,D,mask] =...
2compute_AD(img_i,img_j,center_i,center_j,window_size_h,num_iter,w,num_trans,Dest,mask)
3%
4% function [A,D,mask] = ...
5% compute_AD(img_i,img_j,center_i,center_j,window_size_h,num_iter,w,
6% mask,num_trans)
7%
8% A: Affine motion;
9% D: Displacement;
10%
11% img_i, img_j: the two image(in full size);
12% center_i, center_j: the centers of the feature in two images;
13% window_size_h: half size of the feature window;
14% num_iter: number of iterations;
15% w: parameter used in "grad.m" for computing gaussians used for
16% gradient estimation;
17%
18% num_trans: OPTIONAL, number of translation iteration; default = 3;
19% mask: OPTIONAL, if some area of the square shaped feature window should
20% be weighted less;
21%
22
23%
24% Jianbo Shi
25%
26
27if ~exist('Dest'),
28 Dest = [0,0];
29end
30
31if ~exist('mask'),
32 mask = ones(2*window_size_h+1)';
33end
34
35% set the default num_trans
36if ~exist('num_trans'),
37 num_trans= 3;
38end
39
40% normalize image intensity to the range of 0.0-1.0
41img_i = norm_inten(img_i);
42img_j = norm_inten(img_j);
43
44window_size = 2*window_size_h + 1;
45I = carve_it(img_i,center_i,window_size_h);
46J = carve_it(img_j,center_j,window_size_h);
47
48% init. step
49J_computed = I;
50D_computed = Dest;
51A_computed = eye(2);
52J_computed = compute_J(A_computed,D_computed,img_i,center_i,window_size_h);
53
54%% level of noise
55sig = 0.1;
56
57records = zeros(num_iter,6);
58errs = zeros(1,num_iter);
59
60k = 1;
61% iteration
62while k <= num_iter,
63 [A,D] = iter_AD(J_computed,J,mask,w,k,num_trans);
64
65 A_computed = A*A_computed;
66 D_computed = (A*D_computed')' + D;
67
68 % compute the warped image
69 J_computed = compute_J(A_computed,D_computed,img_i,center_i,window_size_h);
70
71 % compute the SSD error
72 errs(k) = sqrt(sum(sum((mask.*(J_computed-J)).^2)))/prod(size(J));
73
74 % update the mask, discounting possible occlusion region
75 if (k>num_trans),
76 mask = exp(-abs(J_computed-J)/sig);
77 end
78
79 % record the A and D
80 records(k,:) = [reshape(A_computed,1,4),reshape(D_computed,1,2)];
81
82 k = k+1;
83end
84
85[tmp,id] = min(errs);
86A = reshape(records(id,1:4),2,2);
87D = reshape(records(id,5:6),1,2);
88
89J_computed = compute_J(A,D,img_i,center_i,window_size_h);
90mask = exp(-abs(J_computed-J)/sig);