Figure out simple joint formula for sets of vectors?

51 Views Asked by At

I have on the left side four pairs of sample values that result in the respective pair of values on the right side.

[640,  480]  => [245, 225]
[800,  600]  => [305, 280]
[1024, 768]  => [380, 360]
[1280, 1024] => [480, 460]

(Each pair on the left side is the width and height, and each pair on the right site represents x and y coordinates)

Is there a joint formula that could take the value on the left side and transform it to the value on the right side? (It doesn't have to be exact, but it should be within -5 to 5 of the sample values on the right side. For example the first sample set could be [240 to 250, 220 to 230])

For an input (left side) I need to find the result (right side). For example 1280 would end up being about 480, and 1024 would end up as about 460.

For the 4th sample I created this formula:

[w, h] => [x, y]

x = (w/2) - (w/2) * 0.75
y = (h/2) - (h/2) * 0.1

That correctly results in

x = (1280/2) - (1280/2) * 0.75 = 640 - 640 * 0.75 = 640 - 160   = 480
y = (1024/2) - (1024/2) * 0.1  = 512 - 512 * 0.1  = 512 - 52.2  = ~460

But that formula doesn't work for the other ones. For example the second sample would result in

x = (800/2) - (800/2) * 0.75 = 400 - 400 * 0.75 = 400 - 300 = 100, should be 305
y = (600/2) - (600/2) * 0.1  = 300 - 300 * 0.1  = 300 - 30  = 270, should be 280

Can anyone help me please? (And sorry for my bad English. I hope I explained it well enough)

PS: The four samples I provided at the top of my post are just samples. I have 45 in total... should I post them all? THanks

Oh and sorry if I asked wrong it's my first question

1

There are 1 best solutions below

0
On

If you want a linear solution, you need a matrix $X$ such that $AX=B$, being $A=\begin{bmatrix} 640 & 480 \\ 800 & 600 \\ 1024 & 768 \\ 1280 & 1024 \end{bmatrix}$ and $B=\begin{bmatrix} 245 & 225 \\ 305 & 280 \\ 380 & 360 \\ 480 & 460 \end{bmatrix}$.

But this is an incompatible equation.

Then, you can search a least squares solution: solving $A^TAX=A^TB$ we obtain $X\approx \begin{bmatrix} 0.398670 & 0.226749 \\ - 0.029587 & 0.165782 \end{bmatrix}$.

Try this transformation: $$\begin{bmatrix} x \\ y \end{bmatrix}=\begin{bmatrix} 0.398670 & 0.226749 \\ - 0.029587 & 0.165782 \end{bmatrix}^T\begin{bmatrix} w \\ h \end{bmatrix}$$