在python中围绕特定像素旋转图像

发布于 2024-09-16 11:04:59 字数 87 浏览 5 评论 0原文

如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

听不够的曲调 2024-09-23 11:04:59

在 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.

゛时过境迁 2024-09-23 11:04:59

稍微数学一下:如果每个图像的像素位置是向量a,而北极星的位置是p,那么新位置new_p就是

new_p = a + R * (a-p)

R所在的位置旋转矩阵

将会出现问题,因为 new_p 可能不是整数值位置向量。你
可以向后做。对于旋转图像的每个像素应用上述变换的逆,
比你从原始图像中获得像素。由于它也可能不是整数,因此对相邻像素进行采样,如 wu-pixels< /a>(周围散布的点的数量可以用作采样权重)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文