I have 200x380 input image and coordinates (63,146) where (0,0) is top-left:

enter image description here

I rotate about the centre some amount of degrees and expand the "canvas" to avoid cropping resulting in larger output image:

enter image description here

How do I calculate the relative position of point after rotation, with respect to the new larger image?

I'm roughly familiar with how to get the point with respect to the original size but I'm not sure how to transform the calculated new point to fit it in the new image. Red dot is failed attempt of implementing solution transforming the images centre to the 0,0 used in the rotation transform:

enter image description here

My math literacy is not fantastic and I apologise for misusing any terms.

  • 1
    $\begingroup$ The devil is in the details. It appears that you’re able to compute the new bounding box and position the vertices of the transformed rectangle correctly. The very same transformation applies to every other point. Add an explicit example of a failed calculation. $\endgroup$ – amd May 21 at 22:19
  • $\begingroup$ Solved in the end by doing exactly this. I expect my lack of literacy in this field led to not knowing what I was even really looking for... $\endgroup$ – Gavin May 22 at 23:12

Turns out the solution lies in knowing the correct terms to google for.

Put exact implementation here into a function for individual points, using same rotation matrix returned by the image rotate function solved the problem:

def rotate_single_point(point_tuple, rotation_matrix):
    # https://stackoverflow.com/a/38794480/2244284
    # points
    points = np.array([[point_tuple[0],  point_tuple[1]]])
    # add ones
    ones = np.ones(shape=(len(points), 1))
    points_ones = np.hstack([points, ones])
    # transform points
    transformed_points = rotation_matrix.dot(points_ones.T).T
    return transformed_points

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.