summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic/affine/find_D.m
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/affine/find_D.m')
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/affine/find_D.m65
1 files changed, 65 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/toolbox_basic/affine/find_D.m b/SD-VBS/common/toolbox/toolbox_basic/affine/find_D.m
new file mode 100755
index 0000000..1e42cb2
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/affine/find_D.m
@@ -0,0 +1,65 @@
1function D = find_D(I,J,mask,w)
2%
3% function D = find_D(I,J,mask,w)
4%
5% find the vector D such that it minimizes then
6% difference between I(Ax-d)-J(x).
7%
8% mask: the weight matrix,
9% w: window size for estimating gradiant, use a large value
10% when A,D are large.
11%
12
13%
14% NOTE: Because gradient values on the boarder regions of
15% I and J can not be computed accuately when using
16% a gaussian of large support, those boarder regions
17% of width w are not used in computing D.
18%
19
20%
21% Jianbo Shi
22%
23
24[gy1,gx1] = grad(I,w);
25[gy2,gx2] = grad(J,w);
26
27gx = 0.5*(gx1+gx2);
28gy = 0.5*(gy1+gy2);
29
30[size_y,size_x] = size(I);
31[center_y,center_x] = find_center(size_y,size_x);
32mask = mask(w+1:size_y-w,w+1:size_x-w);
33
34[x,y] = meshgrid(1:size_x,1:size_y);
35x = x- center_x;
36y = y-center_y;
37
38x = x(w+1:size_y-w,w+1:size_x-w);
39y = y(w+1:size_y-w,w+1:size_x-w);
40
41gx_sqr = gx.*mask.*gx;
42gx_gy = gx.*mask.*gy;
43gy_sqr = gy.*mask.*gy;
44
45
46T= zeros(2,2);
47
48T(1,1) = 0.5*trapz(trapz(gx_sqr));
49T(2,1) = trapz(trapz(gx_gy));
50T(2,2) = 0.5*trapz(trapz(gy_sqr));
51
52T = T+T';
53
54J = J(w+1:size_y-w,w+1:size_x-w);
55I = I(w+1:size_y-w,w+1:size_x-w);
56
57
58diff = (J-I).*mask;
59b(1) = trapz(trapz(diff.*gx));
60b(2) = trapz(trapz(diff.*gy));
61
62a = inv(T)*b';
63
64D= [a(1),a(2)];
65