<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Yes Denis, i agree that A\B is meaningless, since the 4x4 result can be
applied<br>
to a set of four and only four points and that it has no geometrical
meaning.<br>
<br>
To stick with geometry, a <span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">rotation
o translation o scaling  transform in 2D is linear and affine</span><br>
and then can be described as P2 = A.P1 + B<br>
where A is a 2x2 constant matrix , B is a 2x1 constant column,<br>
P1 is the column of coordinates of a given point<br>
P2 is the column of coordinates of the transformed point<br>
If one wants to transform a whole set of m points,<br>
P1 & P2 should be 2xm matrices (each column is a point in P1 and
its transformed in P2).<br>
<br>
Then, A have 4 coefficients and B have 2 ; so 6 coefficients have to be
determined.<br>
To do that, exactly 3 independant points (=6 coeffs) and their
transform give 6<br>
equations and are needed and sufficient.<br>
<br>
Now, Capitao Obvio is giving 4 points. With all of these, the problem
is overdetermined (8 equations).<br>
This leads to a linear<b> fitting</b> problem, that may be processed
using <b>reglin()</b>:<br>
<br>
Renaming his A => P1  and his B => P2, the best 2x2 A matrix and
2x1 B column<br>
such that P2 = A.P1 + B -- according to a least square criterium -- are
given by<br>
[ A, B ] = reglin(P1,P2);<br>
That gives:<br>
P1 = [<span style="white-space: pre-wrap;"></span> <br>
52.363965, 4.892435 ;<span style="white-space: pre-wrap;"><br>
</span>52.384611, 4.898272 ;<span style="white-space: pre-wrap;"></span><br>
52.379267, 4.881105 ;<span style="white-space: pre-wrap;"></span><br>
52.369678, 4.911489<br>
<div>]<br>
<div>P2 = [<span style="white-space: pre-wrap;"></span><br>
0, 0 ;<span style="white-space: pre-wrap;"></span><br>
2131, 1534 ;<span style="white-space: pre-wrap;"></span><br>
2131, 0 ;<span style="white-space: pre-wrap;"></span><br>
0, 1534</div>
<div>]</div>
<div><br>
-->[A, B] = reglin(P1.',P2.')<br>
<br>
</div>
B  =<br>
  - 5747613.8  <br>
  - 3211459.3  <br>
 A  =<br>
    112982.37  - 34458.388  <br>
    55002.261    67714.214  <br>
<br>
-->A*P1.' + B*ones(P1(:,1).')  // Checking:<br>
 ans  =<br>
 <br>
    5.5829359    2137.0833    2124.8527  - 5.5189172  <br>
  - 35.430415    1495.3941    39.012139    1569.0241  <br>
 <br>
-->P2.'    // To be compared to the previous fit<br>
 ans  = <br>
    0.    2131.    2131.    0.     <br>
    0.    1534.    0.       1534.  <br>
<br>
</div>
<div>-->// For an exact fit, only 3 points must be processed, for
example the 3 first ones:<br>
-->P1 = P1(1:3,:), P2 = P2(1:3,:)<br>
 P1  =<br>
    52.363965    4.892435  <br>
    52.384611    4.898272  <br>
    52.379267    4.881105  <br>
 P2  =<br>
    0.       0.     <br>
    2131.    1534.  <br>
    2131.    0.     <br>
<br>
-->[A, B] = reglin(P1(1:3,:).',P2.')</div>
 B  =<br>
  - 5754011.4  <br>
  - 3170858.6  <br>
 A  =<br>
    113176.65  - 35231.318  <br>
    53769.285    72619.382  <br>
<br>
-->A*P1.' + B*ones(P1(:,1).')  // Checking:<br>
 ans  =<br>
    9.313D-10    2131.    2131.      <br>
    4.657D-10    1534.    4.657D-10  <br>
<br>
-->P2.' <br>
 ans  =<br>
    0.    2131.    2131.  <br>
    0.    1534.    0.     <br>
 <br>
This might help more than A\B ;)<br>
Regards<br>
<br>
Samuel<br>
<br>
<br>
Le 14/10/2011 10:33, CRETE Denis a écrit :
<blockquote
 cite="mid:19088_1318581198_4E97F3CE_19088_340_1_908CBC9017354841B2F32BBEC70A05A101C36B6CA4C1@THSONEA01CMS01P.one.grp"
 type="cite">
  <style>@font-face {
  font-family: "Calibri";
}@font-face {
  font-family: "Tahoma";
}@font-face {
  font-family: "Consolas";
}p.MsoNormal, li.MsoNormal, div.MsoNormal { margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: "Times New Roman","serif"; color: black; }a:link, span.MsoHyperlink { color: blue; text-decoration: underline; }a:visited, span.MsoHyperlinkFollowed { color: purple; text-decoration: underline; }span.EmailStyle17 { font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125); }.MsoChpDefault { font-size: 10pt; }div.WordSection1 { page: WordSection1; }</style>
  <div class="WordSection1">
  <p class="MsoNormal"><span
 style="font-size: 10.5pt; font-family: Consolas; color: rgb(31, 73, 125);">Hello,</span></p>
  <p class="MsoNormal"><span
 style="font-size: 10.5pt; font-family: Consolas; color: rgb(31, 73, 125);">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&sup2; to R&sup2;. Hence,
the transform, if linear, would be described by a 2x2 matrix (and not
4x4). </span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">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:</span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">X=g_x(x,y)</span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">Y=g_y(x,y)</span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">where
x and y are given in the ma trix A and X,Y in B.</span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">The
function g_x and g_y can be expanded to the second order (for the
simplest description of non-linearity)</span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">X=a_x+b_x*x+c_x*y+d_x*x&sup2;+e_x*x*y+f_x*y&sup2;</span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">Y=a_y+b_y*x+c_y*y+d_y*x&sup2;+e_y*x*y+f_y*y&sup2;</span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">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].</span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"> </span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">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</span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">X=a_x
+ b_x*x + c_x*y + d_x*x*y^2</span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">Y=a_y
+ b_y*x + c_y*y + d_y*x^2*y</span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">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.</span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"> </span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">HTH</span></p>
  <p class="MsoNormal"><span
 style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">Denis</span></p>
  </div>
</blockquote>
<br>
Le 12/10/2011 18:25, Capitao Obvio a écrit :
<blockquote
 cite="mid:CAFZz7Xq4O6XgnKGN3g+Ef41L55KieNtwQHSMzqkjVG_P6W7yOA@mail.gmail.com"
 type="cite">
  <div>Hi!</div>
  <div><br>
  </div>
  <div>I'm starting to work with Scilab, and I'm trying to figure out
how to work with matrices.</div>
  <div><br>
  </div>
  <div>
  <div>My goal is to find a way to convert any point from one system
into another.</div>
  <div><br>
  </div>
  <div>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).</div>
  </div>
  <div><br>
  </div>
  <div>Being a bit more specific: </div>
  <div><br>
  </div>
  <div>I have the following points:</div>
  <div><br>
  </div>
  <div>A = [</div>
  <div><span style="white-space: pre-wrap;"> </span>[52.363965,
4.892435],</div>
  <div><span style="white-space: pre-wrap;"> </span>[52.384611,
4.898272],</div>
  <div><span style="white-space: pre-wrap;"> </span>[52.379267,
4.881105],</div>
  <div><span style="white-space: pre-wrap;"> </span>[52.369678,
4.911489],</div>
  <div>]</div>
  <div><br>
  </div>
  <div><br>
  </div>
  <div>They correspond to these points:</div>
  <div><br>
  </div>
  <div>B = [</div>
  <div><span style="white-space: pre-wrap;"> </span>[0, 0],</div>
  <div>
  <span style="white-space: pre-wrap;"> </span>[2131, 1534],</div>
  <div><span style="white-space: pre-wrap;"> </span>[2131, 0],</div>
  <div><span style="white-space: pre-wrap;"> </span>[0, 1534],</div>
  <div>]</div>
  <div><br>
  </div>
  <div>Do you have any suggestions on how to calculate tje transform
from A to B?</div>
  <div><br>
  </div>
  <div>Thanks in advance,</div>
  <div><br>
  </div>
  <div>Cap.</div>
  <div><br>
  </div>
</blockquote>
<br>
</body>
</html>