Reputation: 1
Curently I'm writing a project about image recognition and clusterization. In publication which is a basis for my project there is this equation
Variables description is given below
Rj - is a rotation matrix of j-th cluster
t_j - is a translation vector of j-th cluster
p*ij - is a i-th point from j-th cluster
x_i - is a i-th point from the image
I had a little problem with writing this function so I asked the author of publication if he could share with me a source code. Here is what I got
ddx=D.x-Q.translation(1);
ddy=D.y-Q.translation(2);
st=sin(Q.theta); ct=cos(Q.theta); R=[ct -st; st ct]; % rotation matrix
qq=R*[ppx0; ppy0];
qqd2=sum(qq.*qq,1);
Q.scale=sum((ddx.*qq(1,:)+ddy.*qq(2,:)).*Um) / sum(qqd2.*Um);
Here D.x
, and D.y
are the coordinates of data points
Q.translation
(a vector), Q.scale
, and Q.theta
are the transform parameters
ppx0
and ppy0
are the x- and y- coordinates of *p**ij
Um
is the matrix containing [Umij]
However I have a hard time with understanding this solution. First of all I don't understand why he uses array multiplication (operator .*
) instead of matrix multiplication (operator *
) what is more it seems that he takes only one/first point p*
I hope somebody will help me to try this source code. Thanks in advance
Upvotes: 0
Views: 768
Reputation: 12727
it looks like ppx0
and ppy0
are not coordinates, but rather vectors or coordinates. This way,
R*[ppx0; ppy0] =
[ct -st ; st ct] * [x_0 x_1 ... x_N-1 ; y_0 y_1 ... y_N-1]
Therefore qq
is a 2xN vector, just like [ppx0; ppy0]
.
In qqd2=sum(qq.*qq,1)
, the .*
operator is used, because you're actually squaring every value of a matrix to find the square distance of each of its coordinate pairs later on.
In ddx.*qq(1,:)+ddy.*qq(2,:)
the .*
operator is used as a shortcut to replace a double sum. In other words, istead of taking a sum of each matrix product individually (which in itself is a sum of multiplication), they first performed all necessary multiplications and then took a sum. (I hope this makes sense). You can prove all of these work with some basic matrix algebra.
Upvotes: 1