Finding X,Y coordinates after image rotation
이전 댓글 표시
Hello, I am trying to find the values of some selected points with xy coordinates after rotating an image (90,180,270).
The following code lets me select an option for rotation. Therefore, I created a loop.
Could someone please tell me if my equations are correct?
x1,y1 is the coordinate of a point and x2,y2 is the coordinate of the same point after rotation.
[m,n]=size(image);
% Need rotate?
prompt = {'no rotation: 0; counter clockwise 90: 1, counter clockwise 180: 2,counter clockwise 270: 3'};
dlgtitle = 'Need rotate?';
definput = {'0'};
answer2 = str2double(char(inputdlg(prompt,dlgtitle,[1,80],definput)));
if answer2 == 0
moving = moving;
x2=x1;
y2=y1;
elseif answer2 == 1
moving = rot90(moving,1);
x2=y1;
y2=n-x1;
elseif answer2 == 2
moving = rot90(moving,2);
x2=m-x1;
y2=n-y1;
elseif answer2 == 3
moving = rot90(moving,3);
x2=n-y1;
y2=x1;
else
msg = 'invalid input!';
error(msg)
end
답변 (1개)
Simon Chan
2021년 7월 22일
The following code is going to check the coordinates and not replacing your code, so you may need to verify you code based on the result:
clear; clc;
m = 25; n = 20;
BW = zeros(m,n);
x1=9; y1=7;
BW(y1,x1)=1; % Put one white dot in the image
Result{1} = BW;
Result{2} = rot90(BW,1);
Result{3} = rot90(BW,2);
Result{4} = rot90(BW,3);
[y2, x2] = cellfun(@(x) ind2sub(size(x),find(x)),Result);
And the result shown as follows:
x2 =
9 7 12 19
% x1 y1 n-x1+1 m-y1+1
y2 =
7 12 19 9
% y1 n-x1+1 m-y1+1 x1
댓글 수: 2
Anisha Jamil
2021년 7월 22일
Simon Chan
2021년 7월 22일
I think you are able to verify easily by slightly modifying my previous code:
m = 25; n = 20;
BW = zeros(m,n);
x1=9; y1=7;
BW(y1,x1)=1;
Result{1} = BW;
Result{2} = fliplr(BW);
Result{3} = flipud(BW);
Result{4} = fliplr(flipud(BW));
[y2, x2] = cellfun(@(x) ind2sub(size(x),find(x)),Result)
Result:
y2 =
7 7 19 19
%% y1 y1 m-y1+1 m-y1+1
x2 =
9 12 9 12
%% x1 n-x1+1 x1 n-x1+1
카테고리
도움말 센터 및 File Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!