# Trying to derive a transformation Matrix from a set of known points

by mmacferrin
Tags: derive, matrix, transformation
 P: 88 So, the original points were transformed according to x' = ax + by + c y' = dx + ey + f In order to find the coefficients, pick three points and solve the system |x_1 y_1 1| |a| |x'_1| |x_2 y_2 1| |b| = |x'_2| |x_3 y_3 1| |c| |x'_3| And similarly with d,e,f and y's (you only have to invert the matrix once of course). Unless I screwed up that is :D
 P: 88 Trying to derive a transformation Matrix from a set of known points I guess you're trying to do an inverse perspective transformation then. Let's say that you have the following transformations  a_1*x + a_2*y + a_3 u = ------------------- a_7*x + a_8*y + 1 a_4*x + a_5*y + a_6 v = ------------------- a_7*x + a_8*y + 1 Here (u,v) are the original coordinates, the ones you're trying to recover. Rearranging the above we get a_1*x + a_2*y + a_3 - a_7*xu - a_8*yu = u a_4*x + a_5*y + a_6 - a_7*xv - a_8*yv = v So, assuming we have four pair of points (x_1, y_1), (u_1, v_1) etc we get | x_1 y_1 1 0 0 0 -x_1*u_1 -y_1*u_1 | | a_1 | | u_1 | | x_2 y_2 1 0 0 0 -x_2*u_2 -y_2*u_2 | | a_2 | | u_2 | | x_3 y_3 1 0 0 0 -x_3*u_3 -y_3*u_3 | | a_3 | | u_3 | | x_4 y_4 1 0 0 0 -x_4*u_4 -y_4*u_4 | | a_4 | | u_4 | | 0 0 0 x_1 y_1 1 -x_1*v_1 -y_1*v_1 | | a_5 | = | v_1 | | 0 0 0 x_2 y_2 1 -x_2*v_2 -y_2*v_2 | | a_6 | | v_2 | | 0 0 0 x_3 y_3 1 -x_3*v_3 -y_3*v_3 | | a_7 | | v_3 | | 0 0 0 x_4 y_4 1 -x_4*v_4 -y_4*v_4 | | a_8 | | v_4 | Unless I made a mistake that is :) A bit nastier but not that horrible.
 P: 2 Lord Circ... please excuse my noobieism here but in your post about finding the a , b, c, d, e, f coefficients you have --- In order to find the coefficients, pick three points and solve the system Code: |x_1 y_1 1| |a| |x'_1| |x_2 y_2 1| |b| = |x'_2| |x_3 y_3 1| |c| |x'_3| And similarly with d,e,f and y's (you only have to invert the matrix once of course). --- So to get the d, e, and f is all I have to do is change x'_1, x_2... to y'_1, y'_2 ? so I would have |x_1 y_1 1| |d| |y'_1| |x_2 y_2 1| |e| = |y'_2| |x_3 y_3 1| |f| |y'_3| and solve again for d e f, or do I have to transpose / adjust the values in the leftmost matrix as well?
 P: 12 I know this is an old thread, but I have used its content for something I'm working on at the moment. And after a lot of problems, I found some other references, and want to make a reply for future reference. The above matrix equation (written by Lord Crc) should've said: | x_1 y_1 1 0 0 0 -x_1*u_1 -y_1*u_1 | | a_1 | | u_1 | | 0 0 0 x_1 y_1 1 -x_1*v_1 -y_1*v_1 | | a_2 | | v_1 | | x_2 y_2 1 0 0 0 -x_2*u_2 -y_2*u_2 | | a_3 | | u_2 | | 0 0 0 x_2 y_2 1 -x_2*v_2 -y_2*v_2 | | a_4 | | v_2 | | x_3 y_3 1 0 0 0 -x_3*u_3 -y_3*u_3 | | a_5 | = | u_3 | | 0 0 0 x_3 y_3 1 -x_3*v_3 -y_3*v_3 | | a_6 | | v_3 | | x_4 y_4 1 0 0 0 -x_4*u_4 -y_4*u_4 | | a_7 | | u_4 | | 0 0 0 x_4 y_4 1 -x_4*v_4 -y_4*v_4 | | a_8 | | v_4 | (coefficients doesn't change, the rest (8x8 and 1x8) has changed according to this system: row 1-4 becomes row 1-3-5-7, and row 5-8 becomes row 2-4-6-8) I had some problems with the coefficients being wrong, which made this equation put out wrong values:  a_1*x + a_2*y + a_3 u = ------------------- a_7*x + a_8*y + 1 a_4*x + a_5*y + a_6 v = ------------------- a_7*x + a_8*y + 1` After the reordering of rows, it works perfectly in my code.