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

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

问题描述

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

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

在所有这些文章中,他们都没有解释我们如何围绕自定义枢轴点旋转图像(可以是图像的中心,也可以是偏离实际图像中心的任何其他点).另外,以上帖子中的大多数答案都只是抛出一些代码,而没有过多解释如何针对图像旋转问题实施最近邻技术.有人可以解释如何使用近距离旋转RGB图像(如下图所示).关于自定义枢轴点的邻居(下图中显示的红色标记)?

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 ⎦

r1r2相互关联,因为它们一起形成了单位向量(r1^2 + r2^2 = 1).通过该变换放置坐标时,它们将绕原点旋转.例如,给定向量p,我们通过将其乘以R来将其旋转.

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.

如果要绕另一个点旋转,例如(c1c2),则需要平移坐标,以使新点移动到原点,然后应用旋转,然后平移回去:

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  ⎦

将此乘以得到:

         ⎡ 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天全站免登陆