Calculating coordinates of a pixel in a rotated image
3 views (last 30 days)
Show older comments
I have a binary image and I know the coordinates of a pixel (r, c). I rotate the image by some degrees (I use a rotation matrix) and I need to calculate the new coordinates of the same pixel, in the rotated image. I tried to use common formulas such as
x_new = x_original * cos(angle) - y_original * sin(angle)
y_new = x_original * sin(angle) + y_original * cos(angle)
but this didn't work. Maybe it's because of the MATLAB coordinates system.
After calculating the new coordinates, I need to move the rotated image so that the pixel overlaps another pixel in another image (de facto I am creating a new image right now).
How can I solve the problem?
Thanks in advance.
2 Comments
Rik
on 16 Dec 2022
imrotate rotates images around the center, while these coordinates tend to assume your origin is in the corner. Did you account for this?
Answers (1)
Matt J
on 16 Dec 2022
Edited: Matt J
on 16 Dec 2022
Rather than fussing with your own rotation matrices, you should probably be using imregister or imregtform.
In any case, using your rotation matrix R should have worked, but you need to keep in mind that if spatial coordinates are rotated by θ, then objects in the image will rotate by
. Therefore, you might find you get the correct pixel coordinates if you use R.' instead of R.
0 Comments
See Also
Categories
Find more on Geometric Transformation and Image Registration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!