Hello all,
I'm trying to find the location of a certain pixel after imrotate with crop. Let's say I have an image I of size = (679, 1024) and then I rotate it with imrotate(I, 10, 'crop') for 10 degrees. So here's the original image and the marked pixel:
mat1.png
And here's the rotate image and the marked pixel after rotation:
mat2.png
So the marked pixel at location (354, 32) is transfomred to the new location (303, 64). How do I find the new location only having the rotation angle (10) and the original location?

 Réponse acceptée

Matt J
Matt J le 22 Mar 2019
Modifié(e) : Matt J le 22 Mar 2019
Well, the center of the image in your example is at
c=[512.5;340];
and the rotation matrix expressing the rotation is
R=[cosd(10) +sind(10); -sind(10), cosd(10)]
The transformation of ij=[354; 32] is therefore
>> R*(ij-c)+c
ans =
302.9243
64.2024

4 commentaires

Thank you so much for answering this; but when I use your snippets I get the answer as:
ans =
270.3494
36.8688
Also c should be:
c=[339.5; 512]
right?
UPDATE:
I found out the bug: so here will be the solution:
c = [512; 339.5];
p = [354; 32];
R = [cosd(10) +sind(10); -sind(10), cosd(10)];
p_new = R*(p-c)+c
p_new =
303.0036
64.1080
Thank you so much for the help Matt
Matt J
Matt J le 22 Mar 2019
You're quite welcome, but please Accept-click the answer if it has brought you to a solution.
I will do that! Will you edit your answer so everything is right if people refer to this thread in the future?
Matt J
Matt J le 22 Mar 2019
Modifié(e) : Matt J le 22 Mar 2019
I have fixed the problem with c, but the center is at c=[512.5, 340] because the first pixel is centered at [1;1], not at [0.5;0.5]. Accordingly, my final result for the coordinate of the rotated point should be right as well,
>> p_new = R*(p-c)+c
p_new =
302.9243
64.2024

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by