Anthony wrote:Sorry if I did that then their are too many terms for the FX PerspectiveProjection argument, and the 'Equivelent Command' will not work.
Yes, I see that now in your distort page. You assume the constant in the denominator is 1 and you only excect 8 coeffs. Unfortunately, it is a little inconsistent to have one set of coeffs from fx show 9 values and the other show 8, but I understand your issue.
Here are some experiments:
convert rose: -matte -virtual-pixel transparent -verbose \
-distort Perspective "0,0,0,0 0,46,0,46 70,0,60,10 70,46,60,30" \
+verbose null:
Perspective Projection:
-distort PerspectiveProjection \
'1.97143,-3.04525e-17,4.54175e-16,0.328571,
1,4.44238e-15,0.0185714,-4.38105e-18'
Perspective Distort, FX Equivelent:
-fx 'ii=i+page.x+0.5; jj=j+page.y+0.5;
rr=-0.009420*ii +0.000000*jj + 1;
xx=(+0.507246*ii +0.000000*jj -0.000000)/rr;
yy=(-0.166667*ii +1.000000*jj -0.000000)/rr;
rr>0 ? p{ xx-page.x-.5, yy-page.x-.5 } : blue'
Original: rose.png
Warp by control points:
convert rose: -channel rgba -matte -virtual-pixel transparent -distort Perspective "0,0,0,0 0,46,0,46 70,0,60,10 70,46,60,30" rose_control_pts.png
Then I took the fx coefficients and verified by fx warp:
convert rose: -channel rgba -matte -virtual-pixel transparent -mattecolor none -monitor -fx 'ii=i+page.x+0.5; jj=j+page.y+0.5;
rr=-0.009420*ii +0.000000*jj + 1;
xx=(+0.507246*ii +0.000000*jj -0.000000)/rr;
yy=(-0.166667*ii +1.000000*jj -0.000000)/rr;
rr>0 ? p{ xx-page.x-.5, yy-page.x-.5 } : none' rose_fx.png
Then I put the fx coeffs into -distort perspectiveprojection:
convert rose.png -distort perspectiveprojection ".507,0,0,-.167,1,0,-.00943,0" rose_fx_coeffs.png
But the result was not even close. My understanding of perspective is that the inverse of a perspective transformation is a perspective transformation. Thus I would have thought taking the fx coefficients and using them in -distort perspectiveprojection might have been close, apart from the 0.5 pixel shift.
So then I took the distort perspectiveprojection coeffs and used them as:
convert rose: -channel rgba -matte -virtual-pixel transparent -mattecolor none -distort perspectiveprojection "1.97,0,0,0.329,1,0,0.0185,0" rose_proj_coeffs.png
THIS WORKS. The coefficients are indeed the forward projection coefficients, but the function -distort perspectiveprojection is doing an inverse transformation. Thus Anthony is inverting the coefficient matrix before using it. (As he notes at
http://www.imagemagick.org/Usage/distor ... projection if I had read it more carefully beforehand)
So then I took the coefficients from GIMP:
convert rose: -channel rgba -matte -virtual-pixel transparent -mattecolor none -distort perspectiveprojection "3.55,0,0,.951,.922,0,.0491,-.00169" rose_gimp_coeffs.png
This seems close and the difference could be due the 0.5 pixel shift that is expected in -distort perspectiveprojection. So the GIMP coefficients are GIMPs version of the forward coefficients and not the inverse or reverse mapping coefficients.
Anthony wrote:If you want to do what GIMP is doing try adjusting the input/output coordinates by 0.5. I am just not exactly certian what GIMP does, as in IM the control points are used ASIS for the mathematical calculations.
Unfortunately GIMP does not allow one to supply fractional pixel coordinates. It works only by GUI by dragging the corners, but does give a read out (in the lower left corner of the window) to show you the coordinates.
rick0 wrote:Note: I'm just trying to find a visual and easy way of find the coordinates, and then implement them in IM.
Best I can suggest is to try adjusting the corners of the image in GIMP and write down the old and new coordinate values. The old ones are the original image corners and the new ones are the values shown in the bottom left corner of the window as you drag the corner. Too bad GIMP does not list out the control points, but only their version of the coefficients.