Polynomial Transformation

advertisement
Polynomial Transformations
page 1
Polynomial Transformation
J. Michael Fitzpatrick
CS 359, Fall 2007
BT
T
B
A
Note that, unlike in our previous transformations, T goes from the transformed image
back to the untransformed image. We do this because it is difficult to find the inverse of
nonrigid transformations.
The form of T for a 2D polynomial transformation:
x  a0,0  a1,0 x  a0,1 y  a1,1 xy  a2,0 x 2  a0,2 y 2 
y   b0,0  b1,0 x  b0,1 y  b1,1 xy  b2,0 x 2  b0,2 y 2 
(1)
Note that x and y denote positions in BT while the primed coordinates denote positions in
B. These equations can be written more concisely as follows:
I
J
x   ai , j x i y j
i
j
I
J
y    bi , j x y
i
i
(2)
j
j
In some cases, the summation is limited to polynomials of a specified degree D, in which
case I = J = D and ai , j = bi , j = 0 for i  j  D .
If we know the coefficients, we can calculate the x and y  in B for any x, y in BT. By
calculating them for every x, y in the overlap area (cross-hatched) only, and using
interpolation in B to find the intensity to map into BT, we can transform B into BT in that
area for the purpose of overlaying the transformed B onto A.
How to find the coefficients? By registration, in one of two ways—point registration or
intensity registration. Point registration may be used as an initiation step for intensity
registration. We look at that approach here.
Polynomial Transformations
page 2
Point registration with polynomial transformations.
With point registration, we identify, perhaps visually, a set of point correspondences:
xn , yn  xn , yn ,
(3)
where m ranges from 1 to N. We use those correspondences to determine the ai , j and bi , j .
These are separate problems for a polynomial transformation. The ai , j are determined by
three inputs for every value of n:
xn , yn  xn
(4)
and the bi , j are also determined by three inputs for every value of n:
xn , yn  yn .
(5)
We consider the case I = J = 1 and N = 5. We first find the ai , j . We consider the 5
equations relating the unprimed x’s to the primed x’s and y’s:
x1  a0,0  a1,0 x1  a0,1 y1  a1,1 x1 y1
x2  a0,0  a1,0 x2  a0,1 y2  a1,1 x2 y2
(6)
x5  a0,0  a1,0 x5  a0,1 y5  a1,1 x5 y5
We note that if we form a column vector of primed x coordinates:
 x1 
 x 
 2
x   x3  ,
 
 x4 
 x5 
form a matrix P of combinations of powers of x and y that occur in Eqs. (6):
(7)
Polynomial Transformations
1
1

P  1

1
1
x1
x2
x3
x4
x5
y1
y2
y3
y4
y5
x1 y1 
x2 y 2 

x3 y3  ,

x4 y 4 
x5 y5 
page 3
(8)
and form a column vector c x  of coefficients that appear in Eqs. (6),
c x
 a0,0 
a 
1,0
  ,
 a0,1 
 
 a1,1 
(9)
then we can write those equations this way:
 x1  1
 x  1
 2 
 x3   1
  
 x4  1
 x5  1
or simply
x1
x2
x3
x4
x5
y1
y2
y3
y4
y5
x1 y1 
 a0,0 
x2 y 2   
 a1,0
x3 y3   
  a0,1 
x4 y 4   
a1,1
x5 y5   
x  Pc x  .
(10)
(11)
The analogous equations for y, can be written this way,
 y1  1
 y   1
 2 
 y3   1
  
 y4  1
 y5  1
or simply
x1
x2
x3
x4
x5
y1
y2
y3
y4
y5
y   Pc   ,
y
where c y  is defined similarly to c x  :
x1 y1 
b0,0 
x2 y 2   
 b1,0
x3 y3   
  b0,1 
x4 y 4   
b1,1
x5 y5   
(12)
(13)
Polynomial Transformations
c y 
b0,0 
b 
1,0
  .
 b0,1 
 
 b1,1 
page 4
(14)
At this point we have two problems to solve—the x problem and the y problem. We solve
each of them separately and, because there are more equations than there are unknowns
(for this case 5 equations in 4 unknowns), we find the least-squares solution for each of
them.
2
The least-squares solution to Eq. (11) is the one for which Pc x   x is minimized. Note
that the unknowns here are the coefficients in c x  , not the coordinates in x . There are
standard methods for doing this. One of the best methods employs singular-value
decomposition of P: P  U V t , where U and V are orthogonal matrices of size 5 by 5
and 4 by 4 respectively and   diag  1, 2 , 3 , 4 ,0 . The lambdas are the singular
values of P in decreasing order of size. They are never negative. The least-square solution
is given by
1 1 1 1 
(15)
c x   V diag  , , , ,0 U t x .
 1 2 3 4 
Similarly for the y problem,
1 1 1 1 
c y   V diag  , , , ,0 U t y .
 1 2 3 4 
(16)
A problem will arise if any of the lambdas equal zero. This will happen if all the points
xi yi lie on the same straight line. This least-squares solution can be found very simply in
Matlab. We make these definitions
xp  x;
yp  y ;
(17)
P  P;
and the least-squares solution is found by dividing xp and yp on the left by P :
cx  P \ xp;
cy  P \ yp;
(18)
Then, c x  = cx and c y  = cy .
Once c x  and c y  have been determined, it is a simple matter to transform new points,
Polynomial Transformations
 c x    1 
 a0,0 a1,0 a0,1 a1,1   1 
 x 


 t  
b
 
 y
 
 0,0 b1,0 b0,1 b1,1   x 
 c  y    x 
y
 y .
 
 
 xy 
  xy 
page 5
t
(19)
Which in Matlab becomes:
xp  cx ' r;
yp  cy ' r;
where
r 1 
x
 
y
 
 xy 
(20)
Download