# Thread Subject: find point after imrotate

 Subject: find point after imrotate From: Elad Lachmi Date: 4 Nov, 2009 12:58:02 Message: 1 of 17 Hi all, I have a known point on an image. I rotate the image by say 15 deg and then want to calculate the same point I found before in the rotated image. I tried the following code:  rot_mat=[cosd(deg(I)), sind(deg(I)); -sind(deg(I)) ,cosd(deg(I))];     old_orig = [orig_x orig_y];     new_orig = round(old_orig * rot_mat);     new_orig_x=new_orig(:,1);     new_orig_y=new_orig(:,2); but this does not put my in the right place. Anyone have a clue what I`m doing wrong? Thank you!
 Subject: find point after imrotate From: Brendan Klare Date: 30 Nov, 2009 18:19:18 Message: 2 of 17 "Elad Lachmi" wrote in message ... > Hi all, > I have a known point on an image. I rotate the image by say 15 deg and then want to calculate the same point I found before in the rotated image. > > I tried the following code: > rot_mat=[cosd(deg(I)), sind(deg(I)); -sind(deg(I)) ,cosd(deg(I))]; > old_orig = [orig_x orig_y]; > new_orig = round(old_orig * rot_mat); > new_orig_x=new_orig(:,1); > new_orig_y=new_orig(:,2); > > but this does not put my in the right place. > Anyone have a clue what I`m doing wrong? > > Thank you! Try this: sz = size(image) / 2; orig_x = orig_x - sz(2); orig_y = orig_y - sz(1); rot_mat=[cosd(deg(I)), sind(deg(I)); -sind(deg(I)) ,cosd(deg(I))]; old_orig = [orig_x orig_y]; new_orig =old_orig * rot_mat; new_orig(1) = new_orig(1) + sz(2); new_orig(2) = new_orig(2) + sz(1); In order for this to work you will have to use the 'crop' option in imrotate.
 Subject: find point after imrotate From: Giovanni Ughi Date: 13 May, 2011 12:12:04 Message: 3 of 17 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.
 Subject: find point after imrotate From: ImageAnalyst Date: 13 May, 2011 12:20:51 Message: 4 of 17 Also keep in mind the age old problem with dealing with images. Your coordinates are ordered like (x, y) while matrices are ordered (row, column), which is (y, x). Did you take that into account? It doesn't look like it.
 Subject: find point after imrotate From: Matt J Date: 13 May, 2011 13:10:23 Message: 5 of 17 ImageAnalyst wrote in message <856727ae-9465-4e58-8c35-d50828f025a1@v8g2000yqb.googlegroups.com>... > Also keep in mind the age old problem with dealing with images. Your > coordinates are ordered like (x, y) while matrices are ordered (row, > column), which is (y, x). Did you take that into account? It doesn't > look like it. ============ As a side note, that's only a problem if you accustom yourself to thinking of (row,column) as (y,x).
 Subject: find point after imrotate From: Giovanni Ughi Date: 17 Jun, 2011 13:36:20 Message: 6 of 17 ImageAnalyst wrote in message <856727ae-9465-4e58-8c35-d50828f025a1@v8g2000yqb.googlegroups.com>... > Also keep in mind the age old problem with dealing with images. Your > coordinates are ordered like (x, y) while matrices are ordered (row, > column), which is (y, x). Did you take that into account? It doesn't > look like it. if you are referring to me: I do. If not, no problem.
 Subject: find point after imrotate From: Idil Selin Date: 19 Sep, 2011 10:33:13 Message: 7 of 17 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: Tta=atan((ry-ly)/(rx-lx)) 3. Rim= imrotate(Image2D,Tta,'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(1); orig_y = sz(2); 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" wrote in message ... > 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.
 Subject: find point after imrotate From: Idil Selin Date: 19 Sep, 2011 13:01:28 Message: 8 of 17 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 ... > 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" wrote in message ... > > 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.
 Subject: find point after imrotate From: Matt J Date: 19 Sep, 2011 18:26:27 Message: 9 of 17 "Idil Selin" wrote in message ... > 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? =================== How much error are you seeing? Also, how are you computing orig_x and orig_y? Try rotating a point at (orig_x,orig_y) and see whether it moves. If it moves, it is not the center of rotation.
 Subject: find point after imrotate From: Idil Selin Date: 20 Sep, 2011 13:41:27 Message: 10 of 17 =================== > > How much error are you seeing? Also, how are you computing orig_x and orig_y? Try rotating a point at (orig_x,orig_y) and see whether it moves. If it moves, it is not the center of rotation. Hi Matt, there is a lot of error!!! This is the way I calculate the center of the image: it is its center point (with "x" as a column index) > sz = size(Image2D)/2; > orig_x = sz(2); > orig_y = sz(1); > old_orig = [orig_x orig_y]'; > centered_point=point-old_orig; I am really tired of this rotation. I miss the main point: 1. The angle of imrotate() and the angle of the rotation matrix must be the same or the opposite? 2. I guess I must center the point, apply the rotation and then adding back the same coordinates. All code is the 2 previous e-mail... but it does NOT work. Thank you, Idil
 Subject: find point after imrotate From: Matt J Date: 20 Sep, 2011 13:56:13 Message: 11 of 17 "Idil Selin" wrote in message ... > =================== > > > > How much error are you seeing? Also, how are you computing orig_x and orig_y? Try rotating a point at (orig_x,orig_y) and see whether it moves. If it moves, it is not the center of rotation. > > Hi Matt, > there is a lot of error!!! This is the way I calculate the center of the image: it is its center point (with "x" as a column index) > > sz = size(Image2D)/2; > > orig_x = sz(2); > > orig_y = sz(1); This looks wrong. The geometric center of the image (which is what I think IMROTATE uses) is at sz=size(Image2D)/2+.5;  orig_x = sz(2);  orig_y = sz(1); > 1. The angle of imrotate() and the angle of the rotation matrix must be the same or the opposite? ============== Yes. It makes sense that they are opposite. > 2. I guess I must center the point, apply the rotation and then adding back the same coordinates. > All code is the 2 previous e-mail... but it does NOT work. ================== It should work. Without seeing the errors you get, we can't know what's happening.
 Subject: find point after imrotate From: Matt J Date: 20 Sep, 2011 14:08:17 Message: 12 of 17 "Matt J" wrote in message ... > "Idil Selin" wrote in message ... > > =================== > > > > > > How much error are you seeing? Also, how are you computing orig_x and orig_y? Try rotating a point at (orig_x,orig_y) and see whether it moves. If it moves, it is not the center of rotation. > > > > Hi Matt, > > there is a lot of error!!! This is the way I calculate the center of the image: it is its center point (with "x" as a column index) > > > sz = size(Image2D)/2; > > > orig_x = sz(2); > > > orig_y = sz(1); > > This looks wrong. The geometric center of the image (which is what I think IMROTATE uses) is at > > sz=size(Image2D)/2+.5; > orig_x = sz(2); > orig_y = sz(1); > It looks like you might also have your x,y axes interchanged. I would have expected orig_x = sz(1); orig_y = sz(2);
 Subject: find point after imrotate From: Idil Selin Date: 21 Sep, 2011 08:48:30 Message: 13 of 17 Thank you Matt!!! ... you have got 2 mistakes.... but still is not working.... Example of what happens: size(Image2D)=490*640 %Input image point v=[217.79, 217.09]'; %sample point center of the image c=[245, 320]' %thank you for your tip!!! rot_angle=3.2839 in degree Rot_Im= imrotate(Image2D,Tta,'crop'); RM=[cos(rot_angle) -sin(rot_angle) %Rotation matrix        sin(rot_angle) cos(rot_angle)] temp_v=RM*(v-c) rot_v=temp_v+c =[257.34 425.72]' Now, the first coordinate can be ok, but the 2nd one is totally wrong. The degree of rotation is very little, I was expecting a value near by the 1st coordinate. Any idea? Do you see-understand where is the error? Thank you in advance, Idil
 Subject: find point after imrotate From: Idil Selin Date: 21 Sep, 2011 10:10:26 Message: 14 of 17 Hi, it is me again... as a said in the first message I am working with face landmarks (FL)on the CK+ database. For every image, I do have a set of point, which are the border of the face. When I rotate the image and I try to get the new coordinate points of the FL, the set of rotated points has still the shape of a face BUT it is mirrored: up-down and left-right. Why? Thank you, Idil
 Subject: find point after imrotate From: Matt J Date: 21 Sep, 2011 14:17:29 Message: 15 of 17 "Idil Selin" wrote in message ... > > center of the image c=[245, 320]' %thank you for your tip!!! No. Following my tip, it should be c==[245.5, 320.5]' > RM=[cos(rot_angle) -sin(rot_angle) %Rotation matrix > sin(rot_angle) cos(rot_angle)] Since rot_angle is in degrees (not radians), you need to be using COSD and SIND.
 Subject: find point after imrotate From: Idil Selin Date: 27 Sep, 2011 12:18:13 Message: 16 of 17 Yes Matt, that was the solution! Thank you very much.
 Subject: find point after imrotate From: Gurcan Date: 27 Sep, 2011 12:53:29 Message: 17 of 17 "Idil Selin" wrote in message ... > Yes Matt, that was the solution! Thank you very much. Merhaba Idil Hanim, Elimde baska bir program ile elde ettigim png formtinda bir grafik var. Ben bu grafikteki egrinin altinda kalan alani hesaplamak istiyorum. Nasil yapabilecegim konusunda bir fikir verebilirseniz cok sevinirim. Yardimlariniz icin tesekkur ederim. Gurcan Politecnico di Milano

### Everyone's Tags:

Separated by commas
Ex.: root locus, bode

### What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.