- #1
Sneaky6666
- 14
- 0
I want to try this bilinear transformation of a rectangle to a quad described here
http://www.fmwconcepts.com/imagemagick/bilinearwarp/FourCornerImageWarp2.pdf
on page 4.
I have the square
\(\displaystyle (500,900)(599,900)(599,999)(500,999)\)
and the quad
\(\displaystyle (454,945)(558,951)(598,999)(499,999)\)
It looks like this
Bilinear transformation not working-capture.png
Where the ith entry of the quad and square coordinates above are corresponding corners.
With that in place, I can make the following matrices
\(\displaystyle \begin{bmatrix} 1 & 500 & 900 & 450000 \\ 1 & 599 & 900 & 539100 \\ 1 & 599 & 999 & 598401 \\ 1 & 500 & 999 & 499500 \end{bmatrix} \begin{bmatrix} a_0 \\ a_1 \\ a_2 \\ a_3 \end{bmatrix} = \begin{bmatrix} 454 \\ 558 \\ 598 \\ 499 \end{bmatrix}\)
\(\displaystyle \begin{bmatrix} 1 & 500 & 900 & 450000 \\ 1 & 599 & 900 & 539100 \\ 1 & 599 & 999 & 598401 \\ 1 & 500 & 999 & 499500 \end{bmatrix} \begin{bmatrix} b_0 \\ b_1 \\ b_2 \\ b_3 \end{bmatrix} = \begin{bmatrix} 945 \\ 951 \\ 999 \\ 999 \end{bmatrix}\)
If I solve for them I get
\(\displaystyle a0=-709.911845730028\)
\(\displaystyle a1=1.50964187327824\)
\(\displaystyle a2=0.709621467197225\)
\(\displaystyle a3=-0.000510152025303541\)
\(\displaystyle b0=148.305785123967\)
\(\displaystyle b1=0.611570247933884\)
\(\displaystyle b2=0.85154576063667\)
\(\displaystyle b3=-0.000612182430364249\)
But then when I run this python script (I want to simulate manually, converting the point (454, 945) on the quad to the point (500,900) on the square), I get a different answer. I get (442.90822654, 1024.0)...
Does anyone know what's wrong?
Thanks
http://www.fmwconcepts.com/imagemagick/bilinearwarp/FourCornerImageWarp2.pdf
on page 4.
I have the square
\(\displaystyle (500,900)(599,900)(599,999)(500,999)\)
and the quad
\(\displaystyle (454,945)(558,951)(598,999)(499,999)\)
It looks like this
Bilinear transformation not working-capture.png
Where the ith entry of the quad and square coordinates above are corresponding corners.
With that in place, I can make the following matrices
\(\displaystyle \begin{bmatrix} 1 & 500 & 900 & 450000 \\ 1 & 599 & 900 & 539100 \\ 1 & 599 & 999 & 598401 \\ 1 & 500 & 999 & 499500 \end{bmatrix} \begin{bmatrix} a_0 \\ a_1 \\ a_2 \\ a_3 \end{bmatrix} = \begin{bmatrix} 454 \\ 558 \\ 598 \\ 499 \end{bmatrix}\)
\(\displaystyle \begin{bmatrix} 1 & 500 & 900 & 450000 \\ 1 & 599 & 900 & 539100 \\ 1 & 599 & 999 & 598401 \\ 1 & 500 & 999 & 499500 \end{bmatrix} \begin{bmatrix} b_0 \\ b_1 \\ b_2 \\ b_3 \end{bmatrix} = \begin{bmatrix} 945 \\ 951 \\ 999 \\ 999 \end{bmatrix}\)
If I solve for them I get
\(\displaystyle a0=-709.911845730028\)
\(\displaystyle a1=1.50964187327824\)
\(\displaystyle a2=0.709621467197225\)
\(\displaystyle a3=-0.000510152025303541\)
\(\displaystyle b0=148.305785123967\)
\(\displaystyle b1=0.611570247933884\)
\(\displaystyle b2=0.85154576063667\)
\(\displaystyle b3=-0.000612182430364249\)
But then when I run this python script (I want to simulate manually, converting the point (454, 945) on the quad to the point (500,900) on the square), I get a different answer. I get (442.90822654, 1024.0)...
Code:
X = 454
Y = 945
a0=-709.911845730028
a1=1.50964187327824
a2=0.709621467197225
a3=-0.000510152025303541
b0=148.305785123967
b1=0.611570247933884
b2=0.85154576063667
b3=-0.000612182430364249
A = b2*a3 - b3*a2
C_one = (b0*a1 - b1*a0)
C = C_one + (b1*X - a1*Y)
B_one = (b0*a3 - b3*a0) + (b2*a1 - b1*a2)
B = B_one + (b3*X - a3*Y)
V = (-B + (B*B - 4*A*C)**0.5 ) / (2*A)
U = (X - a0 - a2*V) / (a1 + a3*V)
print U,V
Does anyone know what's wrong?
Thanks
Attachments
Last edited: