2
votes

Having this coordinate system:

And this dominant vertical vanishing point: enter image description here

I would like to rotate the image around x axis so the vanishing point is at infinity. That means that all vertical lines are parallel.

I am using matlab. I find the line segmentes using LSD and the vanishing point using homogeneous coordinates. I would like to use angle-axis representation, then convert it to a rotation matrix and pass this to imwarp and get the rotated image. Also would be good to know how to rotate the segments. The segments are as (x1,y1,x2,y2).

Image above example:

Vanishin point in homogenous coordinates:

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

Vanishin point in cartesian coordinates (what you see in the image):

(x,y) = [190.1335 -838.3577]

Question: With this vanishing point how do I compute the rotation matrix in the world x axis as explained above?

1
you want an affine transform/homographyAnder Biguri
You mean something like rotMat = vrrotvec2mat([u, theta]) ?user5128199
That doesn't work Jon. I just don't know how to do it @JonDamia Fuentes
3D rotations have a lot of ambiguities, and convention-dependent parts, so it's hard to just plug-and-play. If you can add more to your question, like a small example of actual code and example numbers, I might be able to help.user5128199
Updated question @Jon Would be great if you can help me.Damia Fuentes

1 Answers

1
votes

If all you're doing is rotating the image so that the vector from the origin to the vanishing point, is instead pointing directly vertical, here's an example.

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

You can play with the negatives, and plotting, since I'm not sure about those parts applying to your situation. The negatives may come from plotting upside down, or from rotation of the world vs. camera coordinate system, but I don't have time to think about it right now.

EDIT

If you want to rotation about the X-axis, this might work (adapted from https://www.mathworks.com/matlabcentral/answers/113074-how-to-rotate-an-image-along-y-axis), or check out: Rotate image over X, Y and Z axis in Matlab

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