|
Dear all,
it is again me. I will try to formulate a more clear question:
1. I rotate the original image using:
Rim=imrotate(image2D, - rotate_angle_in_degree)
2. I need to find out the new coordinate of P(x,y):
2.1 I subtract the center of the image to the coordiante of P:
Centered_P(x-orig_x, y-orig_y)
2.2 I rotate Centered_P using a rotation matrix:
Rot_Matrix=[cos(rot_angle) -sin(rot_angle);
sin(rot_angle) cos(rot_angle)]
New_P=Rot_Matrix*Centered_P;
%Notice that the angle used by imrotate() and the one of the Rot_Matrix are oppowsite. Isn't it?
2.3 What else? I cannot find the same point in the rotated image.... What I am missing?
Thank you, Idil
"Idil Selin" wrote in message <j575p9$g5$1@newscl01ah.mathworks.com>...
> Hi Giovanni,
> to me it does NOT work, and I need it asap. Can you help me? Thanks in any case.
> I work with the CK+ dataset which has 2D faces + landskape, I need to align the face and crop it. Every face has 68 face landmarks (FL), size(FL)=2*68, FL(1,:) is the x coordinate, the column. The size of every picture is 490*640, the center point is (245, 320).
> 1. for every face I know the (x,y) of the center of the eyes: (lx, ly) (rx,ry)
> 2. I calculate the angle of the line joining the 2 center eyes: rot_angle=atan((ry-ly)/(rx-lx))
> 3. Rim= imrotate(Image2D,-rot_angle,'loose') to rotate the original image. Isn't it?
> 4. Now I want to find the new coordinates of the FL. Because I have greyscale pictures, my rotation matrix is 2*2:
> Rot_Matrix=[cos(rot_angle) -sin(rot_angle);
> sin(rot_angle) cos(rot_angle)]
> 4.1 I convert FL coordinates with respect to the center of the image:
> sz = size(Image2D)/2;
> orig_x = sz(2);
> orig_y = sz(1);
> old_orig = [orig_x orig_y]';
> centered_FL=FL-repmat(old_orig, [1,68]);
> 4.2 I calculate the new coordinates of FL:
> temp_FL=Rot_Matrix*centered_FL;
> New_FL=temp_FL';
>
> When I try to plot this new FL most of them are OUT of the picture (while the original FL where all around the original face). Where do I make a mistake?
> Thank you in advance.
> Idil
>
> "Giovanni Ughi" <giovanni.ughi@gmail.com> wrote in message <iqj76k$6fq$1@newscl01ah.mathworks.com>...
> > I would suggest to simply use a rotation matrix
> > Rx = [1 0 0;
> > 0 cos(rot_angle) -sin(rot_angle);
> > 0 sin(rot_angle) cos(rot_angle)];
> > (rot_angle must be expressed in radians)
> >
> > then if your points are in an array like this
> > A = [1 x y
> > 1 x y
> > 1 x y
> > 1 x y
> > ...
> > ]
> >
> > solution would be Rx*(A')
> > of course keep in mind that x,y coordinates must refer to the center of the image
> > hope it helps! to me it has always worked perfectly.
|