Calculating coordinates of a pixel in a rotated image

3 views (last 30 days)
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
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?
Banzai
Banzai on 16 Dec 2022
Moved: Matt J on 16 Dec 2022
In the end I managed to calculate the point in another way.
Now I need to overlap the two images on a specific point. I tried using imtranslate to move one image by the vector
[x_1-x_2, y_1-y_2] and imfuse to fuse them together. It kinda works but imfuse changes the color of the images (and I don't want that) and crops the image I have moved (and I don't want that either). How can I solve this issue?

Sign in to comment.

Answers (1)

Matt J
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.

Community Treasure Hunt

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

Start Hunting!