Sign in to follow this  
Lode

What's the name of this transformation?

Recommended Posts

Lode    1003
Hi, I programmed a transformation with the intention of perspective correction on a 2D image, but I'm actually wondering if it is really a correct perspective correction transformation, and, what transformation it is. It works like this: you choose 4 points, each point can be at any position on the source image. In the result image, point 1 becomes the top left corner, point 2 the top right corner, point 3 the bottom right corner, point 4 the bottom left corner. For all pixel values in between, I simply take the weighed average of the positions between the 4 chosen points. By weighed average, I mean for example, the center pixel of the result image, is the point where two lines in the source image cross that connect the centers of the lines between the 4 points (see bottom most image below). The image below explains this better: It's the fact that there are non-straight lines in some of the images on the right that concerns me. So I don't use any 3D matrix at all, just weighed averages of positions. Do you know if this transformation can be represented by a 3D matrix as well, and if not, what transformation it actually is, and if it can be correctly used for perspective correction (I think it can)?

Share this post


Link to post
Share on other sites
haegarr    7372
Its a kind of image warping and as such generally not an elemental transformation. To express it as a matrix you need to solve (in column vector notation)
M * p1 == [ 0 1 ]T
M * p2 == [ 1 1 ]T
M * p3 == [ 1 0 ]T
M * p4 == [ 0 0 ]T
for M which gives 8 equations with 8 independent variables if I've counted correctly (homogeneous matrix for 2D). So it should be possible in general. EDIT: Nope, I haven't counted correctly. You get 8 equations for 6 variables if you go for linear equations, and 12 equations for 8 variables if you use the homogeneous vector, too. (Hopefully now it's correct.)

Share this post


Link to post
Share on other sites
alvaro    21266
You can find a 3x3 matrix that represents a projectivity that maps the corners the way you want and that transforms straight lines into straight lines. The process is tricky, and especially tricky to do robustly, but it can be done. In odd cases, like you third picture, where two sides of the quadrilateral cross, you may end up not preserving the notion of what points are inside.

What are you trying to achieve exactly? (EDIT: Sorry, I am not paying attention today. You seem to be trying to do perspective correction, and the projectivity I mentioned above is the right thing to do for that purpose. Another name for that type of transformation is "homography".)

Share this post


Link to post
Share on other sites
Lode    1003
Quote:
Original post by alvaro
What are you trying to achieve exactly? (EDIT: Sorry, I am not paying attention today. You seem to be trying to do perspective correction, and the projectivity I mentioned above is the right thing to do for that purpose. Another name for that type of transformation is "homography".)


So do I understand it correctly that what I'm doing above is not a perspective correction but something else?

Share this post


Link to post
Share on other sites
alvaro    21266
Quote:
Original post by Lode
So do I understand it correctly that what I'm doing above is not a perspective correction but something else?

Well, I don't quite understand what you did, because the weight combination of the four vertices that would yield a particular point inside the quadrilateral is not uniquely determined. But no, it can't possibly be a perspective correction because it doesn't preserve straight lines.

Share this post


Link to post
Share on other sites
Lode    1003
Here's exactly what I do:

The source image is e.g. 400x400 pixels, and the destination image is also 400x400 pixels.

In the source image, 4 points (point 1, 2, 3 and 4) are chosen.

In the destination image, it loops through every pixel, and gets the relative coordinates (e.g. pixel 200,200 has relative coordinates 0.5,0.5).

Then it takes the relative X position (e.g. 0.5) between points 1 and 2, and between points 3 and 4, in the source image. This gives two new points, A and B.

Then it takes the relative Y position (e.g. also 0.5 in the example above) between points 1 and 4, and between points 2 and 3. Name these point for example "C" and "D".

Then it gets the intersection point of the lines AB and CD, name that for example "E".

Then the resulting pixel gets the color of the pixel that was at E in the source image.

I still have no idea what transformation that is, all that apparently turns out is that it doesn't preserve straight lines and thus can't be a correct perspective correction. Which is a shame because this seemed such a convenient method :(

So I'll look up how to do it properly now.

EDIT: had typed a wrong method, fixed it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this