Image Rectification
2007-10-09
Premise
Image rectification is the process of taking a perspective image and altering by ways of a perspective matrix to a rectangle or square. In these notes, I will outline the steps necessary to complete this procedure. For some of the mathematical equations and demonstration purposes, I will be using matlab.
The Image
The image shown above has the points (c,d,f,g) which have the pixel coordinates shown. We can use this information to get the points at infinity. As a rule, the cross product of points give the equations of the lines that connect them. Also the cross product of lines give the points of intersection. Thus we can say,
l1 = c x g and l2 = f x d
intersection of l1 and l2 = l1 x l2
The intersections of parallel lines in projective space is thus, (-436,-101,1) and (1117, -80, 1). Next, we want to send the points at infinity to the points (1,0,0) and (0,1,0). But, we already have 4 points, why do we need the points at infinity? Well, it makes solving the matrix much easier. Here is the system of equations that I will work with.
| M |
|
|
|
~ |
|
|
|
Sent a point from infinity ~ (p1) |
| M |
|
|
|
~ |
|
|
|
Sent a point from infinity ~ (p2) |
| M |
|
|
|
~ |
|
|
|
Sent a point from (0 0 1) ~ (p3) |
| M |
|
|
|
~ |
|
|
|
Sent a point from (1 1 1) ~ (p4) |
Looking at this set of equations, we can see that the matrix M consists of M = [ αp1 | β p2 | γ p3 ]. That is, we can see that the matrix M just consists of points p1, p2, and p3 scaled by some α, β, and γ scalar. Seeing that the fourth matrix is equal to M, we can solve for α, β, and γ.
Solving for α, β, and γ
In matrix form, we can see that
We can take the inverse of [p1 p2 p3] and multiply it by p4 to then get the α, β, γ values. Solving for M in matlab gives us the following.
H = [[-436 -101 1];[1117 -80 1];[207 170 1]]'
v = inv(H)*[209 245 1]'
M = [v(1)*[-436 -101 1];v(2)*[1117 -80 1]; v(3)*[207 170 1]]'
I take the inv(M) and hit it with a scale (of 300) and then take the transpose which matlab wants to put into the maketform('projective', M)
Here is the result
