Finding X,Y coordinates after image rotation
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Simon Chan
am 22 Jul. 2021
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 Kommentare
Simon Chan
am 22 Jul. 2021
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
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!