source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/zisserman/vgg_numerics/vgg_mrdivs.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

  • Property svn:executable set to *
File size: 1.6 KB
Line 
1% vgg_mrdivs  Solves equation system Y*diag(s) = A*X with unkowns A, s.
2%
3% A = vgg_mrdivs(X,Y) solves (overdetermined) equation system Y*diag(s) = A*X
4% by linear method (DLT algorithm).
5% Parameters:
6%   X ... double (N,K)
7%   Y ... double (M,K)
8%   A ... double (M,N)
9%   s ... double (1,K)
10%
11% Preconditioning of the points not included in the function. Use vgg_conditioner_*.
12%
13% Typical usage:
14%   1. Estimating an image homography from K pairs of corresponding points.
15%      If 3-by-K matrices x and y are the points in homogeneous coordinates, the 3-by-3 homography
16%      matrix is obtained as H = vgg_mrdivs(x,y).
17%
18%   2. Estimating 3-by-4 camera projection matrix P from corresponding pairs of image and scene points.
19%      For image points x (3xK matrix) and scene points X (4xK matrix) do P = vgg_mrdivs(X,x).
20
21% (c) werner@robots.ox.ac.uk
22
23% Algorithm:
24%
25% For n-th point pair X(:,n) and Y(:,n) we have
26%  s*X(:,n) = A*Y(:,n)
27% We eliminate s what results in MY*(MY-1)/2 linear homogenous equations
28% for elements of A. We solve this system by svd or eig.
29
30function A = vgg_mrdivs(X,Y)
31
32[MX,N] = size(X);
33[MY,NY] = size(Y);
34if N ~= NY, error('Matrices A, B must have equal number of columns.'); end
35
36 % construct the measurement matrix
37W = zeros(MX*MY,MY*(MY-1)/2*N);
38k = 1;
39for i = 1:MY
40  for j = 1:i-1
41    W([[1:MX]+MX*(j-1) [1:MX]+MX*(i-1)],[1:N]+N*(k-1)) =  [(ones(MX,1)*Y(i,:)).*X; -(ones(MX,1)*Y(j,:)).*X];
42    k = k+1;
43  end
44end
45
46% solve the system || A'(:)' * W || ---> min
47[dummy,s,A] = svd(W',0);
48A = reshape(A(:,end),MX,MY)';
49
50return
Note: See TracBrowser for help on using the repository browser.