我们如何使用最近邻插值算法围绕自定义枢轴点旋转 RGB 图像? [英] How can we rotate an RGB image using nearest neighbor interpolation algorithm about a custom pivot point?

查看:15
本文介绍了我们如何使用最近邻插值算法围绕自定义枢轴点旋转 RGB 图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解计算机视觉中的图像插值算法.我意识到有大量的插值技术,如线性、双三次、最近邻等用于图像旋转.似乎最近邻技术是该领域中最简单的算法.我了解基本概念,例如当我们使用旋转矩阵旋转图像时,由于余弦和正弦运算,新的图像行和列变为浮点值.因此,我们必须截断浮点值并进行插值以预测丢失图像坐标处的数据......我知道与这个问题非常相关的三个帖子: 这里):

 ⎡ r1 -r2 0 ⎤R = ⎢ r2 r1 0 ⎥⎣ 0 0 1 ⎦

r1r2 是相关的,它们一起形成一个单位向量 (r1^2 + r2^2 = 1).当通过该变换放置坐标时,它们围绕原点旋转.例如,给定一个向量 p,我们通过左乘 R 来旋转它.

如果你想围绕另一个点旋转,比如 (c1, c2),你需要平移坐标,使这个新点移动到原点,然后应用旋转,然后翻译回来:

 ⎡ 1 0 c1 ⎤ ⎡ r1 -r2 0 ⎤ ⎡ 1 0 -c1 ⎤T' R T = ⎢ 0 1 c2 ⎥ ⎢ r2 r1 0 ⎥ ⎢ 0 1 -c2 ⎥⎣ 0 0 1 ⎦ ⎣ 0 0 1 ⎦ ⎣ 0 0 1 ⎦

乘以得出:

 ⎡ r1 -r2 -r1*c1+r2*c2+c1 ⎤ ⎡ 1 0 -r1*c1+r2*c2+c1 ⎤ ⎡ r1 -r2 0 ⎤T' R T = ⎢ r2 r1 -r2*c1-r1*c2+c2 ⎥ = ⎢ 0 1 -r2*c1-r1*c2+c2 ⎥ ⎢ r2 r1 0 ⎥⎣ 0 0 1 ⎦ ⎣ 0 0 1 ⎦ ⎣ 0 0 1 ⎦

因此,我们可以看到,我们可以简单地围绕原点旋转,然后以某种适当的方式平移结果,以获得与围绕我们选择的旋转中心旋转相同的结果.

给定任何旋转图像并给出完整结果的图像处理库函数(即其输出图像包含所有输入数据),我们可以通过将该结果切割为输入大小来重新创建围绕任意点旋转的结果适当的偏移量.

I am trying to understand image interpolation algorithms in computer vision. I realize that there are a ton of interpolation techniques like linear, bicubic, nearest neighbor, etc. for image rotation. It seems that nearest neighbor technique is the simplest algorithm in this area.. I understand the basic concepts like when we rotate an image with a rotation matrix, the new image rows and columns go to floating point values because of cosine and sine operations. Thus we have to truncate the floating point values and do interpolations to predict data at missing image coordinates... I am aware of three posts which are very relevant to this question : Post 1; Post 2 and Post 3

In all of these posts, they do not explain how can we rotate an image about a custom pivot point (could be center of image or any other point which is offset from the real image center). Also most of the answers in the above posts just throw some code without much explanation about how the nearest neighbor technique is implemented for an image rotation problem... Can someone explain how to rotate an RGB image (like the image shown below) using nearest neighbor about a custom pivot point (red mark shown in the image below) ?

解决方案

A simple rotation is always about the origin. A simple rotation (in 2D) is given by the following transformation matrix (I'm using homogenous coordinates here):

    ⎡ r1 -r2 0 ⎤
R = ⎢ r2  r1 0 ⎥
    ⎣ 0   0  1 ⎦

r1 and r2 are related in that together they form a unit vector (r1^2 + r2^2 = 1). When putting coordinates through that transformation, they are rotated about the origin. For example, given a vector p, we rotate it by left-multiplying it by R.

If you want to rotate around another point, say (c1, c2), you need to translate the coordinates such that this new point moves to the origin, then apply the rotation, then translate back:

         ⎡ 1 0 c1 ⎤  ⎡ r1 -r2 0 ⎤  ⎡ 1 0 -c1 ⎤
T' R T = ⎢ 0 1 c2 ⎥  ⎢ r2  r1 0 ⎥  ⎢ 0 1 -c2 ⎥
         ⎣ 0 0 1  ⎦  ⎣ 0   0  1 ⎦  ⎣ 0 0  1  ⎦

Multiplying this out gives:

         ⎡ r1 -r2 -r1*c1+r2*c2+c1 ⎤   ⎡ 1 0 -r1*c1+r2*c2+c1 ⎤  ⎡ r1 -r2 0 ⎤
T' R T = ⎢ r2  r1 -r2*c1-r1*c2+c2 ⎥ = ⎢ 0 1 -r2*c1-r1*c2+c2 ⎥  ⎢ r2  r1 0 ⎥
         ⎣ 0   0   1              ⎦   ⎣ 0 0  1              ⎦  ⎣ 0   0  1 ⎦

So, we can see that we can instead simply rotate around the origin, and then translate the result in some appropriate way to get the same result as if we were rotating around our chosen center of rotation.

Given any image processing library function that rotates the image and gives the full result (i.e. its output image contains all input data), we can recreate the result of rotating around an arbitrary point by cutting this result to the input size with the appropriate offset.

这篇关于我们如何使用最近邻插值算法围绕自定义枢轴点旋转 RGB 图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆