[scilab-Users] Matrix transformations

CRETE Denis denis.crete at thalesgroup.com
Fri Oct 14 10:33:15 CEST 2011


Hello,
I do not agree with the approach given below, as the transform acts on the plane (RxR) to another plane, i.e. it acts from R² to R². Hence, the transform, if linear, would be described by a 2x2 matrix (and not 4x4).
It is very plausible that the initial difficulty (finding a linear transform such as rotation o translation o scaling) comes from a distortion of the "picture" on which a "path" should be mapped (these terms are generic). So, the transform is not linear; it can be represented by the system:
X=g_x(x,y)
Y=g_y(x,y)
where x and y are given in the ma trix A and X,Y in B.
The function g_x and g_y can be expanded to the second order (for the simplest description of non-linearity)
X=a_x+b_x*x+c_x*y+d_x*x²+e_x*x*y+f_x*y²
Y=a_y+b_y*x+c_y*y+d_y*x²+e_y*x*y+f_y*y²
The 12 coefficients a_x, a_y, b_x, b_y... f_x and f_y are determined with the points contained in A and B. However, the number of points must be increased to 6 in order to get 12 equations (giving [X_1;Y_1;X_2;Y_2...X_6 ;Y_6] as a product of a 12x12 matrix C and the vector [a_x; a_y;b_x;...f_y]) which can be inverted to get the vector [a_x, a_y,b_x,...f_y] as a product of the 12x12 matrix inv(C) and the vector [X_1;Y_1;X_2;Y_2...X_6;Y_6].

But with usual optical distortion, it is likely that the second order terms are zero (when the origin is chosen at the center of the image) and the 3rd order terms should be considered. One can try the following
X=a_x + b_x*x + c_x*y + d_x*x*y^2
Y=a_y + b_y*x + c_y*y + d_y*x^2*y
with proper choice of the origin (center of the image). Only the matrix C needs to be changed (each pair of row is [1,x_i,y_i,x_i*y_i^2; 1,x_i,y_i,x_i^2*y_i] for i=1...4) , otherwise the procedure is the same as for the 2nd order case presented above. I have already used this kind of transform to correct image distortion. In this case, careful selection of the points is necessary: I fear that choosing the 4 corners of the image is not appropriate. Choosing the center, one corner and 2 "middle-side" points  of the image might give better results.

HTH
Denis

De : Samuel Gougeon [mailto:sgougeon at free.fr]
Envoyé : mercredi 12 octobre 2011 20:07
À : users at lists.scilab.org
Objet : Re: [scilab-Users] Matrix transformations

Hi,

If you assume that the transform is linear and can be described by
a matrix T such that  B = T*A, then you merely get T as
T = B / A
-->T = B/A
 T  =

    0.    0.           0.           0.
    0.    80113.778  - 80081.268    0.
    0.  - 11913.312    11955.211    0.
    0.    92027.09   - 92036.479    0.

then, checking that T*A gives B :
-->T*A
 ans  =
    0.           0.
    2131.        1534.
    2131.        1.455D-11
  - 9.313D-10    1534.

-->B
 B  =
    0.       0.
    2131.    1534.
    2131.    0.
    0.       1534.

// So, it's OK. T*A has some residues as big as ~10^-10 instead of 0, due to
// numerical approximations (finite number of digits in inputs and during
// the processing).

Then, if you wish to decompose T as a rotation o translation o scaling,
it is an additional piece of work.

HTH
Samuel

Le 12/10/2011 18:25, Capitao Obvio a écrit :
Hi!

I'm starting to work with Scilab, and I'm trying to figure out how to work with matrices.

My goal is to find a way to convert any point from one system into another.

My (failed) approach so far was to estimate the necessary rotation, translation and scale; but it didn't work quite well, because the second map is slightly distorted (probably due perspective).

Being a bit more specific:

I have the following points:

A = [
[52.363965, 4.892435],
[52.384611, 4.898272],
[52.379267, 4.881105],
[52.369678, 4.911489],
]


They correspond to these points:

B = [
[0, 0],
[2131, 1534],
[2131, 0],
[0, 1534],
]

Do you have any suggestions on how to calculate tje transform from A to B?

Thanks in advance,

Cap.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20111014/609bf8d1/attachment.htm>


More information about the users mailing list