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

If have Image Processing TB, check out
doc imrotate
I used this code to find the angle between the two points
ang = atan2 (y2-y1, x2-x1);
then applied this process
B = imrotate (img, ang);
But I did not get the result I wanted.
I want the path between the two points to be identical to the x-axis after the image is rotated
KALYAN ACHARJYA
KALYAN ACHARJYA 2018년 9월 13일
Attach the original image.
jonas
jonas 2018년 9월 13일
When you use the word identical, do you mean parallel to the x-axis?
Jan
Jan 2018년 9월 13일
@wisam kh: "But I did not get the result I wanted." What do you get instead?
dpb
dpb 2018년 9월 13일
편집: dpb 2018년 9월 13일
ang = atan2 (y2-y1, x2-x1);

which point is 1, which is 2 in the image? You have to be sure to ask to rotate in the proper direction to counteract the computed angle, not compound it.

wisam kh
wisam kh 2018년 9월 13일
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 2018년 9월 13일
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

댓글을 달려면 로그인하십시오.

 채택된 답변

Amir Xz
Amir Xz 2018년 9월 13일

1 개 추천

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);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

질문:

2018년 9월 11일

댓글:

2018년 9월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by