Effacer les filtres
Effacer les filtres

Rotate image parallel to the x-axis

5 vues (au cours des 30 derniers jours)
wisam kh
wisam kh le 11 Sep 2018
Commenté : wisam kh le 14 Sep 2018
Hello
If I select two points in the picture, and then I extracted the angle between this two points, (note between them line to clarify) Like this picture:
Can I rotate the image so that the path between these two points is parallel to the x-axis, as in the following picture?
I mean if I have two points in a gray or binary image, I want to rotate this image so that the path between the two points is parallel to the X axis.
thank you
  8 commentaires
wisam kh
wisam kh le 13 Sep 2018
Sorry if my question is unclear.
I mean if I have two points in a gray or binary image, I want to rotate this image so that the path between the two points is parallel to the X axis.
dpb
dpb le 13 Sep 2018
It's not the Q? that's unclear, I was pointing out you must define which direction the angle is defined from and ensure you do the rotation to negate the angle as opposed to adding to it...
As others said, your description of what is not as expected is not useful

Connectez-vous pour commenter.

Réponse acceptée

Amir Xz
Amir Xz le 13 Sep 2018
A = [50 70]; %[x y] & x,y: pixel number
B = [100 30]; %[x y]
% find point2 (point with larger x)
if A(1)>B(1)
P2 = A; P1 = B;
else
P2 = B; P1 = A;
end
% clockwise OR counterclockwise
if P2(2)<P1(2)
w=-1; % clockwise
else
w=+1; % counterclockwise
end
angle = w*atan(abs(P2(2)-P1(2))/(P2(1)-P1(1)))*180/pi; % deg
ImgRot = imrotate(Img,angle);
  1 commentaire
wisam kh
wisam kh le 14 Sep 2018
Thank you very much
The code works fine.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Geometric Transformation and Image Registration dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by