Page 1 of 1

### Prespective Transformations in IM

Posted: 2006-12-11T00:33:04-07:00
After some heavy discussions about the methematics of perspective transformations, and the generating of the appropriate formulas, with 'Hugemann' in the IM forums, I can now present the results of that discussion.

The following is a 'proof of concept' for perspective transformations, in IM Examples.
http://www.cit.gu.edu.au/~anthony/graph ... erspective

Note that the final formula involved 8 floating point values, which unlike the 6 used for affine transformations do not relate specifically to variuos 'linear' transfortations. It is also EXTREMELY slow, due to the amount of parsing needed by the FX expression.

It is hoped that the formula will soon become a IM built in function, though may need a 8 dimmensional matrix solver to be added to IM, if we want the input to be in terms of 2 (before,after) by 4 coordinates.

Posted: 2006-12-11T19:24:59-07:00
Anthony: I tried out your transformation example but didn't get quite the same result as you did:
http://members.shaw.ca/el_supremo/build ... formed.png

I'm using 6.3.0 Q8. Would the Q8 version make a difference to the result?

Pete

Posted: 2006-12-11T21:13:22-07:00
All the numbers are in image coordinates and color should have no effect.
Actually as all colors are normalised quality shouldn't effect the fx formulas either

Hmmm are you sure you have the input numbers right?

Are the constants in the formula generated by the "perspective_transform" script the same?
There are 8 numbers all floating point and any change in one will effect the whoel result.

DID your reverse the 2 sets of coordinates? Destination set first, then original image set?
I have done a lot of editing to try to make it clear that it is the REVERSE transformation
EG destination coordinate to source coodrinate
that is actually needed and used by the distortion algorithim.

Posted: 2006-12-11T21:47:19-07:00
I've got Perl installed on my WinXP system but I can't get the matrix package to install. So I just cut your result:

Code: Select all

``````det=-0.003057*i + -0.000389*j + 1;
xx=(0.533277*i + -0.033042*j + 5.690943)/det;
yy=(-0.392491*i + 0.833446*j + 15.611041)/det;
``````
and pasted it into the appropriate place in the convert command and used the input image from your website.

Pete

Posted: 2006-12-12T06:55:49-07:00
That is very strange then because what is displayed on the IM Examples webpage is the actual code and results used to generate that webpage. I designed it that way to ensure there is a direct one to one match with what I use and what results I get.

Hugemann is working of a VB equivelent to the perl script that includes its own Gussian Elimination Algorithim to solve the equations needed to convert the coordinates into the 8 constants shown in the formula. This formula actually generates a perspective matrix.

You can check the foruma by substituting a destination coordinate for the i,j values, and see if you get the appropriate x,y values in the original image.

That is 100,123 actually maps to 85,122 I verified this by hand, so the forumla is correct. As such something must be wrong with the -fx application for your version of IM.
The Version number of the IM that was used is given at the bottom of every IM Examples page. Every time I re-generate all the examples that last image on the page is also updated to reflect the IM version used (under linux).

As for the Math::MatirxReal. The 'pm' file in the CPAN distribution isn't compiled but used as is. so you should have no problems installing it. Hmmm The version of the module I am using (personal install) is version 2.01, which is the latest. which can be downloed from http://leto.net/code/Math-MatrixReal/

I used it as I have it available, as I basied my own Perl Module contribution Math::VectorReal, data store on that same format providing cross and dot multiplication for row matrix vectors. That is proper vector math operators for 3d vector handling.
This was done as part of my studies in Polyhedral Objects.

Posted: 2006-12-12T08:27:07-07:00
I installed IM 6.3.1 and now it produces the same image.
I also installed MatrixReal and got the perspective transform to work.

Pete

Posted: 2006-12-12T16:35:03-07:00
Good. Was the new version also Q8?

Posted: 2006-12-12T19:05:42-07:00
Yes, I usually install Q8.

Pete