围绕世界 x 轴旋转图像

Rotate image around world x axis

有这个坐标系:

这个主要的垂直消失点:

我想绕 x 轴旋转图像,使消失点位于无穷远。这意味着所有垂直线都是平行的。

我正在使用 matlab。我使用 LSD 找到线段,使用齐次坐标找到消失点。我想使用角度轴表示,然后将其转换为旋转矩阵并将其传递给 imwarp 并获取旋转图像。也很高兴知道如何旋转线段。这些段为 (x1,y1,x2,y2)。

上图示例:

齐次坐标中的消失点:

(x,y,z) = 1.0e+05 * [0.4992   -2.2012    0.0026]

笛卡尔坐标中的消失点(您在图像中看到的):

(x,y) = [190.1335 -838.3577]

问题:有了这个消失点,我如何计算如上所述的世界 x 轴上的旋转矩阵?

如果您所做的只是旋转图像,使从原点到消失点的矢量直接垂直,下面是一个示例。

I = imread('cameraman.tif');
figure;imagesc(I);set(gcf,'colormap',gray);

vp=-[190.1335 -838.3577,0]; %3d version,just for cross-product use,-ve ?
y=[0,1,0]; %The vertical axis on the plot
u = cross(vp,y); %you know it's going to be the z-axis
theta = -acos(dot(vp/norm(vp),y)); %-ve ?
rotMat = vrrotvec2mat([u, theta]);
J=imwarp(I,affine2d (rotMat));
figure;imagesc(J);set(gcf,'colormap',gray); %tilted image

你可以玩玩底片和策划,因为我不确定这些部分是否适用于你的情况。底片可能来自颠倒的绘图,或者来自世界与相机坐标系的旋转,但我现在没有时间考虑它。

编辑

如果您想绕 X 轴旋转,这可能有效(改编自 https://www.mathworks.com/matlabcentral/answers/113074-how-to-rotate-an-image-along-y-axis), or check out:

[rows, columns, numberOfColorChannels] = size(I);
newRows = rows * cos(theta);
rotatedImage = imresize(I, [newRows, columns]);