The -verbose output of -distort outputs two sets of values...
Forward mapping "projection" coefficents, and the FX equivelent reversed mapping that distort actually performs.
Perspective I have direct examples for...
For example (from the IM Exmaples page, Perspective Internals)
http://www.imagemagick.org/Usage/distor ... _internals
Code: Select all
Perspective Projection:
-distort PerspectiveProjection \
'1.430099, 0.246650, 3.000000, 0.147296,
1.434591, 0.000000, 0.006757, 0.009448'
Perspective Distort, FX Equivelent:
-fx 'ii=i+page.x+0.5; jj=j+page.y+0.5;
rr=-0.004119*ii -0.005877*jj + 1;
xx=(+0.711858*ii -0.108326*jj -2.135575)/rr;
yy=(-0.073090*ii +0.699571*jj +0.219269)/rr;
rr>0 ? p{ xx-page.x-.5, yy-page.y-.5 } : blue' \
The first set is the forward mapping values for the perspective matix, as used by "PerspectiveProjection"
in the order sx, ry, tx, rx, sy, ty, px, py
See PrespectiveProjection
http://www.imagemagick.org/Usage/distor ... projection
the other part is the reversed mapping algorithm using the inverse perspective matrix values in the for of a FX expression.
That is the equivelent of what the Distort is actually doing! But using px, py values first to generate teh divisor, then using the sx, ry, tx, rx, sy, ty values to map distination ii,jj to source xx,yy values (floating point)
Now the forward mapped values is what you need to map any specific point in the source image to the distination image.
This is exampled in Layed Images, Positioning Distorted Layer Images
http://www.imagemagick.org/Usage/layers/#layer_distort
I use an "awk" script to do the mathematical calculations, after extracting the values directly from the Verbose output (such as that shown above).
Affine (or SRT) is simplier as you do not have the Px and Py parts. (Affine is perspective with out changing scale)
From your previous posts the part you want is...
Code: Select all
-distort AffineProjection \
'0.939693,0.342020,-0.342020,0.939693,63.256300,-41.744302'
This represents (as per
Affine Projection)
the values... sx, rx, ry, sy, tx, ty as a forward mapping!
NOTE: the slight reordering of the tx and ty values. This differance is just a traditional ordering for Affine Matrix values, and is the same ordering used for a old IM setting and operation "-affine" & = "-transform" whcih "-distort replaced, but is still available.
Affine transforms are looked at in detail on a older set of IM Example pages that has become its own 'sub-page'.
Affine Matrix Transforms
http://www.imagemagick.org/Usage/distorts/affine/
Some mathematical examples are given on that page too, as well as much more detail of what each component actually does to images.