diff options
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/affine/compute_AD.m')
-rwxr-xr-x | SD-VBS/common/toolbox/toolbox_basic/affine/compute_AD.m | 90 |
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 @@ | |||
1 | function [A,D,mask] =... | ||
2 | compute_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 | |||
27 | if ~exist('Dest'), | ||
28 | Dest = [0,0]; | ||
29 | end | ||
30 | |||
31 | if ~exist('mask'), | ||
32 | mask = ones(2*window_size_h+1)'; | ||
33 | end | ||
34 | |||
35 | % set the default num_trans | ||
36 | if ~exist('num_trans'), | ||
37 | num_trans= 3; | ||
38 | end | ||
39 | |||
40 | % normalize image intensity to the range of 0.0-1.0 | ||
41 | img_i = norm_inten(img_i); | ||
42 | img_j = norm_inten(img_j); | ||
43 | |||
44 | window_size = 2*window_size_h + 1; | ||
45 | I = carve_it(img_i,center_i,window_size_h); | ||
46 | J = carve_it(img_j,center_j,window_size_h); | ||
47 | |||
48 | % init. step | ||
49 | J_computed = I; | ||
50 | D_computed = Dest; | ||
51 | A_computed = eye(2); | ||
52 | J_computed = compute_J(A_computed,D_computed,img_i,center_i,window_size_h); | ||
53 | |||
54 | %% level of noise | ||
55 | sig = 0.1; | ||
56 | |||
57 | records = zeros(num_iter,6); | ||
58 | errs = zeros(1,num_iter); | ||
59 | |||
60 | k = 1; | ||
61 | % iteration | ||
62 | while 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; | ||
83 | end | ||
84 | |||
85 | [tmp,id] = min(errs); | ||
86 | A = reshape(records(id,1:4),2,2); | ||
87 | D = reshape(records(id,5:6),1,2); | ||
88 | |||
89 | J_computed = compute_J(A,D,img_i,center_i,window_size_h); | ||
90 | mask = exp(-abs(J_computed-J)/sig); | ||