5

I would like to rotate an object in an image in Matlab. I'm trying this code:

I = imread('MPE.jpg');
imagesc(I);
theta=90
tform = affine2d([cosd(theta) -sind(theta) 0; sind(theta) cosd(theta) 0; 0 0 1]);
J = imwarp(I,tform);
h=imagesc(J);
end
bad_coder
  • 11,289
  • 20
  • 44
  • 72
achraf
  • 51
  • 5
  • Can you add/link to the original image without the ellipses you added please? – BillBokeey May 10 '16 at 08:17
  • 2
    Are you sure you want a rotation? From the image it looks like you want a stretch and translation (and perhaps also a rotation, but not necessarily). If so, I believe you need to precede it with scalar in front of the affine transform, to introduce stretch. – Steve Heim May 10 '16 at 08:22
  • i want to do a geometric transformation ,if you see in the first image, i see a ellipse and i want to see the object face to see a circle, – achraf May 10 '16 at 08:36
  • i want to a rotation about the vertical axis of the object – achraf May 10 '16 at 09:17
  • Consult the duplicate link. What you need to do is specify control points for the surface before warping and after warping. The duplicate should explain things nicely. – rayryeng May 10 '16 at 13:52
  • i want to do a rotation about the vertical axis of the object in the red circle , to see the face of object – achraf May 10 '16 at 14:02
  • Did you even read the duplicate? – rayryeng May 10 '16 at 14:02
  • yes , i read it , it's not the same thing , i want to rotate the object about the verticale axis , in the red circle you see the object in the corner , i have to rotate it to see it in the center of the image – achraf May 10 '16 at 14:10

1 Answers1

0

One technique could be to have bounding box (BB) to red and green contours. Resize red BB to green BB with imresize(). Then, you can easily rotate resized portion to the desired angle by using imrotate().

Chandra
  • 96
  • 1
  • 10
  • if I resize the image i will lose the variable pixel , i didn't understand your idea , can you explain your idea ?? – achraf May 10 '16 at 08:29
  • what do you mean by variable pixel? – Chandra May 10 '16 at 08:31
  • As long as there is no angle differences between red and green areas, there is no need of imrotate. Resizing taking care of roll rotation of the object. – Chandra May 10 '16 at 08:34
  • I want to do a geometric transformation ,if you see in the first image, i see a ellipse and i want to see the object face to see a circle, – achraf May 10 '16 at 08:37
  • if i lose the variable pixel, i can't calculate the characteristic of the object and also i can't make the graphique – achraf May 10 '16 at 08:40
  • if you want to convert elliptical object to circular object with no planer rotation..then the above technique will work......However, if your requirement is more general then you need to decide the similar and corresponding points of both shapes and then calculate tform. Then you can use imwarp () – Chandra May 10 '16 at 08:48
  • how i can calculate tform , i used a matrix rotation 3d but it rotate all the object, and i want to see object face – achraf May 10 '16 at 08:54
  • i want to a rotation about the vertical axis of the object – achraf May 10 '16 at 09:17
  • Have corresponding points from both contours....e.g. in your case of red and green contours, you can take extreme left of both shapes as corresponding points, similarly extreme right, extreme top and extreme bottom. You can try with newer version MATLAB's function like estimateFundamentalMatrix available in MATLAB 2016a – Chandra May 10 '16 at 09:22
  • but best method is the with bounding box if you have same planer angles of ellipse and circle/ellipse.... – Chandra May 10 '16 at 09:23
  • rotation about vertical axis is called as roll rotation in robotics. For this specific case bounding box method will work perfectly. – Chandra May 10 '16 at 09:26
  • can you send me the script ,if you have it to try this method – achraf May 10 '16 at 09:33