math - 如何旋转图像?

标签 math image-processing

See also: Why is my image rotation algorithm not working?



这个问题不是特定于语言的,而是一个数学问题。然而,我将使用一些 C++ 代码来解释我需要什么,因为我对数学不太感兴趣。

以下是图像的组成方式:
ImageMatrix image;
image[0][0][0] = 1;
image[0][1][0] = 2;
image[0][2][0] = 1;
image[1][0][0] = 0;
image[1][1][0] = 0;
image[1][2][0] = 0;
image[2][0][0] = -1;
image[2][1][0] = -2;
image[2][2][0] = -1;

这是我要创建的函数的原型(prototype):
ImageMatrix rotateImage(ImageMatrix image, double angle);

我只想旋转前两个索引(行和列),而不是 channel 。

最佳答案

解决这个问题的常用方法是倒着做。不是计算输入图像中的每个像素最终在输出图像中的位置,而是计算输出图像中的每个像素在输入图像中的位置(通过在另一个方向上旋转相同的量。这样你可以确定输出图像中的所有像素都有一个值。

output = new Image(input.size())

for each pixel in input:
{
  p2 = rotate(pixel, -angle);
  value = interpolate(input, p2)
  output(pixel) = value
}

有不同的方法来做插值。对于旋转公式,我认为您应该检查 https://en.wikipedia.org/wiki/Rotation_matrix#In_two_dimensions

但为了好看,这里是(点(x,y)角度/弧度的旋转):
 newX = cos(angle)*x - sin(angle)*y
 newY = sin(angle)*x + cos(angle)*y

关于math - 如何旋转图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/695080/

相关文章:

c++ - 元素的每一个和的可能性

python - 如何使用opencv python(hough Circles)找到给定图像中的圆?

.net - .NET检测灰度图像

algorithm - 如何确定点是否在 3D 三角形内?

c++ - 如何控制 OpenCV findContours 中点的顺序?

image-processing - WebGL 地球 : how to make clouds

python - 字符分割不适用于3,8

C#:函数求值顺序(相对于 C)

javascript - 根据内容长度设置显式模式宽度

algorithm - n 算法的基 b 扩展