Structure from Motion by Factorization: From the Camera Equation to 3D, Step by Step
In the earlier posts of this series we saw what Structure from Motion (SfM) does: it takes many photos of an object and recovers both the 3D shape and the camera positions. This post walks through one complete method, with all the maths. It is the factorization method of Tomasi and Kanade (1992). You only need vectors, matrices and matrix multiplication.
Step 1: The pinhole camera equation
Put the camera at the origin, looking along the Z axis. A point in front of it is at (X, Y, Z). Light from the point goes straight through the pinhole and lands on the image at (u, v). Similar triangles give:

Here f is the focal length. Dividing by Z is why far objects look small. It is also what makes these equations hard: they are not linear.
Step 2: When the object is far away
Let the object sit at distance Z0 and let its own depth be small:
Then the division becomes the same for every point:
Every point is scaled by the same number, so we can choose units where f / Z0 = 1 (we assume the camera stays at about the same distance in every photo). This simple camera is called orthographic: it just drops the depth.

Now let the camera turn and move between photos. (From here on, the letter f counts the photos: photo 1, photo 2, …, photo F. The focal length is already absorbed in the units.) In photo f, the camera’s “right” direction is a unit vector if and its “down” direction is a unit vector jf, perpendicular to each other. A 3D point sp appears at

The dot product measures how far the point lies along each camera axis; af and bf are the shifts of the image. This is linear, and that is all we need.
Step 3: The observation matrix
A feature tracker follows P points through F photos. We write every measurement into one table, the observation matrix W: the first F rows hold the u values (one row per photo), the next F rows hold the v values, and each column belongs to one point.


Step 4: Remove the shifts and see the hidden structure
Put the world origin at the centre (average) of all the points. Then the average of each row of W is exactly af or bf. Subtract each row’s average and the shifts disappear. Call the result W̃:
This is exactly a matrix product. Stack the camera directions as rows into the motion matrix M, and the points as columns into the structure matrix S:
Key fact. W̃ can be large (24 × 30 in our example), but it is a product of a matrix with 3 columns and a matrix with 3 rows. So its rank is at most 3: every row is a mix of just three basic rows.
The question is how to split W̃ back into M and S. The tool is the SVD.
Step 5: What is the singular value decomposition (SVD)?
Every matrix A, of any shape, can be written as
- U and V have orthonormal columns (unit length, at right angles). They act like rotations.
- Σ is diagonal. Its entries σ1, σ2, … are the singular values.
Read it as “rotate, stretch, rotate”. Each singular value says how strongly A stretches along one direction. A singular value of zero means that direction is squashed flat.
To compute them: the squares σ2 are the eigenvalues of ATA. A small example:
Only one singular value is non-zero, so A has rank 1. That makes sense: its two rows are the same.
Two facts we will use:
1. Rank of a matrix = number of non-zero singular values.
2. Keeping only the k largest singular values (and setting the rest to zero) gives the best possible rank-k approximation of the matrix (Eckart–Young theorem).
Step 6: Factorize the observation matrix
Real tracks have a little noise, so W̃ is not exactly rank 3. But its SVD shows three large singular values and the rest tiny. In our simulation they are 16.8, 13.2, 6.0, and then 0.09 or less. We keep the three large ones:
and split Σ3 evenly between the two sides:
By fact 2, this is also the best rank-3 fit to the noisy data.

Step 7: Fix the leftover ambiguity
There is one catch. For any invertible 3 × 3 matrix Q:
So M̂ and Ŝ are only correct “up to Q“. A wrong Q stretches or shears the shape. We find Q from what we know about real cameras: in every photo, if and jf have length 1 and are perpendicular. Write m̂ for the rows of M̂ and set L = QQT. Then:
L is symmetric, so it has only 6 unknowns, and these equations are linear in them. F photos give 3F equations, solved by least squares. Q then comes from L by a Cholesky factorization (a “square root” for symmetric matrices). Finally:
The rows of M are the camera directions in every photo (motion). The columns of S are the 3D points (structure).
How well does it work?
In the simulation: 30 points on a small house, 12 photos, noise added to the tracks. After the steps above, the camera rows of M have length 1.00, as they should. The recovered shape matches the true one within 0.019 units, for an object 2 units wide. Two things cannot be recovered from the photos alone. The first is the overall rotation of the world; every SfM method has this freedom, so we compare shapes after the best rotation. The second is a mirror flip in depth, which is special to the orthographic camera: a shape and its mirror image look the same in every photo.
Limits
The method assumes the object is far away (orthographic camera) and that every point is seen in every photo. Modern tools such as COLMAP use the full pinhole equation, add photos one by one, and refine everything with bundle adjustment. The idea that motion and structure can be separated with linear algebra still sits underneath.
Reference: C. Tomasi and T. Kanade, “Shape and motion from image streams under orthography: a factorization method”, International Journal of Computer Vision, 9(2), 137–154, 1992.

Comentarios · 1