1
$\begingroup$

I'm having trouble solving the following problem. Hopefully someone can help!

The following is in homogeneous coordinates. I am projecting a point into a pinhole camera. $\lambda$ is an unknown scaling factor, all other variables are known.

$\mathbf{x} = \mathtt{P}(\lambda \mathbf{X} + \mathbf{Q})$

P is a 3x4 projection matrix. I'd like to solve for $\lambda$. Here's some example data:

x = [-0.4052 -0.0502 1.0000]'
P = [1     0     0     0
     0     1     0     0
     0     0     1     0]
X = [0.3925 0.0465 -0.9313 1.0000]'
Q = [-18.4299, 0, -7.7678, 1.0000]'

And for this data, I know $\lambda$ is about 1430 if I just brute force search. Plugging the numbers and this result into the equation gives a correct solution. However, surely there must be a direct solution for $\lambda$? I can't seem to work it out!

Thanks,

John

  • 0
    You can't solve directly for $\lambda$ without additional assumptions. Given $Q$ and $X$, $\lambda$ parameterizes a 1-d space (call it $\Lambda$) and $x$ parameterizes a 3-d space. There will only be a $\lambda$ that solves this equation if $x$ is in the image of $\Lambda$ under the mapping $P$.2011-05-09
  • 0
    Thanks for your help Chris. $x$ is actually a 2D space because I'm using homogeneous coordinates (http://www.riemers.net/eng/ExtraReading/homogenous_matrices.php). I will draw graphically what I am trying to solve and it might help... my maths is pretty poor, hence my bad explanation (and trouble solving the problem!). Also, here's a plot of $|\mathbf{x} - \mathtt{P}(\lambda \mathbf{X} + \mathbf{Q})|$: http://imgur.com/xDHJv. I would like to minimize this error.2011-05-09
  • 0
    Ah, if you're just interested in minimizing the error, you can solve it. See my answer below.2011-05-09

2 Answers 2

1

I think what you actually want is the following: calling $y = P ( \lambda X + Q)$, you want $\left( \frac{y_1}{y_3}, \frac{y_2}{y_3} \right)$ to be as close to $\left( \frac{x_1}{x_3}, \frac{x_2}{x_3} \right)$ as possible.

If so, then the target function to minimize is $\left| \left( \frac{x_1}{x_3} - \frac{y_1}{y_3} \right)^2 + \left( \frac{x_2}{x_3} - \frac{y_2}{y_3} \right) \right|^2$, which is a function of the form $$ \frac{\alpha \lambda^2 + 2 \beta \lambda + \gamma}{\left( \lambda X_3 + Q_3 \right)^2} $$ with $\alpha = (x_3 X_1 - x_1 X_3)^2 + (x_3 X_2 - x_2 X_3)^2$, $\beta = (x_3 X_1 - x_1 X_3) (x_3 Q_1 - x_1 Q_3) + (x_3 X_2 - x_2 X_3) (x_3 Q_2 - x_2 Q_3)$, and $\gamma = (x_3 Q_1 - x_1 Q_3)^2 + (x_3 Q_2 - x_2 Q_3)^2$.

This system has a simple minimum at $$ \lambda = \frac{\beta Q_3 - \gamma X_3}{\beta X_3 - \alpha Q_3}, $$ which in your case turns out to be close to 1426.3

  • 0
    This looks even better, but I'm concerned that $P$ is not in the solution... have you made an error writing up your answer?2011-05-09
  • 0
    I think that Michael has used the specific P that you gave in your question.2011-05-09
  • 0
    Ah, of course. Thanks again!2011-05-09
1

Notice that $|x-P(\lambda X + Q)|$ is minimized exactly when $|x-P(\lambda X + Q)|^2$ is minimized. We can rewrite this as

$$|x-PQ-\lambda PX|^2 = |x-PQ|^2 - 2\lambda(x-PQ)^TPX + \lambda^2 X^TP^TPX$$

which is simply a quadratic in $\lambda$. To minimize it we set its derivative to zero, giving

$$\lambda X^TP^TPX = (x-PQ)^TPX$$

which we solve for $\lambda$ to give

$$\lambda = \frac{(x-PQ)^TPX}{X^TP^TPX}$$

Edit: for the example you gave, this gives an optimal $\lambda$ of -1.068, in contrast to your value of ~1400. I'm not sure why the discrepancy arises.

  • 0
    Thanks, the discrepancy is probably to do with the use of homogeneous coordinates. When you calculate $\mathtt{P}(\lambda \mathbf{X} + \mathbf{Q})$, $x$ will be 3x1. $x$ needs to be normalised so that x(3) = 1. Anyway, thanks very much for your help, I've got something working now.2011-05-09