在python中围绕特定像素旋转图像
如何在 Python 中围绕特定像素旋转图像?我正在尝试对一组夜空图像进行反旋转。由于星星围绕北极星旋转,我可以将北极星定义为旋转中心并旋转每个图像以排列星星。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 phadej 的回答中,图像上某个点的新旧坐标之间的变换是 仿射变换。
PIL(Python 图像库)有一个名为
transform
的图像方法它可以执行图像的仿射变换。transform
的文档位于此页面的底部附近。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.稍微数学一下:如果每个图像的像素位置是向量
a
,而北极星的位置是p
,那么新位置new_p
就是R所在的位置旋转矩阵。
将会出现问题,因为 new_p 可能不是整数值位置向量。你
可以向后做。对于旋转图像的每个像素应用上述变换的逆,
比你从原始图像中获得像素。由于它也可能不是整数,因此对相邻像素进行采样,如 wu-pixels< /a>(周围散布的点的数量可以用作采样权重)。
With a little math: if each image's pixel position is vector
a
, and position of Polaris isp
, then new positionnew_p
iswhere R is Rotation matrix.
There will be problem, as
new_p
is probably not an integer valued position-vector. Youcan 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).