2

How can I rotate an image about a specific pixel in Python? I am trying to de-rotate a set of images of the night sky. Since the stars rotate around Polaris, I could define Polaris as the center of rotation and rotate each image to line up the stars.

2
  • 2
    Once you work out how to rotate an image about a specific pixel, how do you programmatically define the location of Polaris? Commented Aug 25, 2010 at 22:49
  • 1
    Polaris does not move (or moves very little), and therefore is always on the same pixel. So I can just define it's location in pixel coordinates. Commented Aug 25, 2010 at 22:53

2 Answers 2

2

In phadej's answer the transformation between the old and new coordinates of a point on the image is an affine transformation.

PIL (Python Imaging Library) has an image method called transform which can perform an affine transformation of an image.

The documentation for transform is near the bottom of this page.

Sign up to request clarification or add additional context in comments.

Comments

0

With a little math: if each image's pixel position is vector a, and position of Polaris is p, then new position new_p is

new_p = a + R * (a-p)

where R is Rotation matrix.

There will be problem, as new_p is probably not an integer valued position-vector. You can do it backwards. For each pixel of rotated image apply the inverse of above transform, than you will get pixel from original image. As it could be not integer also, sample the neighbor pixels like in wu-pixels (the amount of dot spread around can be used as the sampling weight).

1 Comment

I'm sure there is some library to do it for you, but it's nice programming exercice. For example imagemagick has this kind of "distortion" built-in: imagemagick.org/script/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.