Prespective Transformations in IM
 anthony
 Posts: 8877
 Joined: 20040531T19:27:0307:00
 Authentication code: 8675308
 Location: Brisbane, Australia
Prespective Transformations in IM
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.
Comments welcome.
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.
Comments welcome.
Anthony Thyssen  Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/

 Posts: 1015
 Joined: 20050321T21:16:5707: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
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
 anthony
 Posts: 8877
 Joined: 20040531T19:27:0307:00
 Authentication code: 8675308
 Location: Brisbane, Australia
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.
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.
Anthony Thyssen  Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/

 Posts: 1015
 Joined: 20050321T21:16:5707: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:
and pasted it into the appropriate place in the convert command and used the input image from your website.
Pete
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;
Pete
 anthony
 Posts: 8877
 Joined: 20040531T19:27:0307:00
 Authentication code: 8675308
 Location: Brisbane, Australia
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 regenerate 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/MathMatrixReal/
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.
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 regenerate 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/MathMatrixReal/
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.
Anthony Thyssen  Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/

 Posts: 1015
 Joined: 20050321T21:16:5707:00
 anthony
 Posts: 8877
 Joined: 20040531T19:27:0307:00
 Authentication code: 8675308
 Location: Brisbane, Australia
Good. Was the new version also Q8?
Anthony Thyssen  Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/