28
$\begingroup$

I have a camera matrix (I know both intrinsic and extrinsic parameters) known for image of size HxW. (I use this matrix for some calculations I need).

I want to use a smaller image, say: $\frac{H}{2}\times \frac{W}{2}$ (half the original). What changes do I need to make to the matrix, in order to keep the same relation ?

I have, $K$ as the intrinsic parameters, ($R$,$T$ rotation and translation)

$$\text{cam} = K \cdot [R T]$$

$$K = \left( \begin{array}&a_x &0 &u_0\\0 &a_y &v_0 \\ 0 &0 &1\end{array} \right)$$

$K$ is 3*3, I thought on multiplying $a_x$, $a_y$, $u_0$, and $v_0$ by 0.5 (the factor the image was resized) , but I'm not sure.

$\endgroup$

2 Answers 2

20
$\begingroup$

Note: That depends on what coordinates you use in the resized image. I am assuming that you are using zero-based system (like C, unlike Matlab) and 0 is transformed to 0. Also, I am assuming that you have no skew between coordinates. If you do have a skew, it should be multiplied as well

Short answer: Assuming that you are using a coordinate system in which $u' = \frac{u}{2} , v' = \frac{v}{2}$, yes, you should multiply $a_x,a_y,u_0,v_0$ by 0.5.

Detailed answer The function that converts a point $P$ in world coordinates to camera coordinates $(x,y,z,1)->(u,v,S)$ is:

$$ \left( \begin{array}{ccc} a_x & 0 & u_0 \\ 0 & a_y & v_0 \\ 0 & 0 & 1 \end{array} \right) \left( \begin{array}{ccc} R_{11} & R_{12} & R_{13} & T_x \\ R_{21} & R_{22} & R_{23} & T_y \\ R_{31} & R_{32} & R_{33} & T_z \\ 0 & 0& 0 & 1 \end{array} \right) \left( \begin{array}{ccc} x \\ y \\ z \\ 1 \end{array} \right) $$

Where $(u,v,S)->(u/S,v/S,1)$, since the coordinates are homogenous.

In short this can be written as $ u= \frac{m_1 P}{m_3 P} , v = \frac{m_2 P}{m_3 P}$
where $M$ is the product of the two matrixes mentioned above, and $m_i$ is the i'th row of the matrix $M$. (The product is scalar product).

Re-sizing the image can be thought of:

$$ u'=u/2, v'=v/2 $$

Thus

$$ u' = (1/2) \frac {M_1 P} {M_3 P} \\ v' = (1/2) \frac {M_2 P} {M_3 P} $$

Converting back to matrix form gives us:

$$ \left( \begin{array}{ccc} 0.5 & 0 & 0 \\ 0 & 0.5 & 0 \\ 0 & 0 & 1 \end{array} \right) \left( \begin{array}{ccc} a_x & 0 & u_0 \\ 0 & a_y & v_0 \\ 0 & 0 & 1 \end{array} \right) \left( \begin{array}{ccc} R_{11} & R_{12} & R_{13} & T_x \\ R_{21} & R_{22} & R_{23} & T_y \\ R_{31} & R_{32} & R_{33} & T_z \\ 0 & 0& 0 & 1 \end{array} \right) \left( \begin{array}{ccc} x \\ y \\ z \\ 1 \end{array} \right) $$

Which is equal to

$$ \left( \begin{array}{ccc} 0.5 a_x & 0 & 0.5 u_0 \\ 0 & 0.5 a_y & 0.5 v_0 \\ 0 & 0 & 1 \end{array} \right) \left( \begin{array}{ccc} R_{11} & R_{12} & R_{13} & T_x \\ R_{21} & R_{22} & R_{23} & T_y \\ R_{31} & R_{32} & R_{33} & T_z \\ 0 & 0& 0 & 1 \end{array} \right) \left( \begin{array}{ccc} x \\ y \\ z \\ 1 \end{array} \right) $$

For additional information, refer to Forsyth, chapter 3 - Geometric camera calibration.

$\endgroup$
3
  • $\begingroup$ Thanks a lot for the explanation !!! I'm just no so sure what you mean by zero-based system , I'm using matlab, do I need any other adjustments ? $\endgroup$
    – matlabit
    Nov 21, 2012 at 15:31
  • $\begingroup$ @matlabit, If you are using Matlab, you should use the transformation with $u' = (u-1)/2 + 1 , v' = (v-1)/2 + 1$, since it has one-based indexing (First element is 1, not 0). Try to compute the relevant matrix in this case. If you do not need sub-pixel accuracy, you can just ignore it and use the formula I gave you. $\endgroup$ Nov 21, 2012 at 19:15
  • $\begingroup$ You do not need the [0 0 0 1] row in the [R|t] matrix. The [R|t] matrix should be 3x4, and not 4x4. Your current equations fail because 3x3 matrix cannot be multiplied by a 4x4 matrix. $\endgroup$
    – simplename
    Dec 21, 2021 at 23:08
11
$\begingroup$

Andrey mentioned that his solution assumes 0 is transformed to 0. If you are using pixel coordinates this is likely not true when you re-size the image. The only assumption you really need to make is that your image transformation can be represented by a 3x3 matrix (as Andrey demonstrated). To update your camera matrix you can just premultiply it by the matrix representing your image transformation.

[new_camera_matrix] = [image_transform]*[old_camera_matrix]

As an example, say you need to change the resolution of an image by a factor $2^n$ and you are using 0 indexed pixel coordinates. Your coordinates are transformed by the relationships

$x' = 2^n*(x+.5)-.5$

$y' = 2^n*(y+.5)-.5$

this can be represented by the matrix

$ \left( \begin{array}{ccc} 2^n & 0 & 2^{n-1}-.5 \\ 0 & 2^n & 2^{n-1}-.5 \\ 0 & 0 & 1 \end{array} \right) $

so your final camera matrix would be

$ \left( \begin{array}{ccc} 2^n & 0 & 2^{n-1}-.5 \\ 0 & 2^n & 2^{n-1}-.5 \\ 0 & 0 & 1 \end{array} \right) \left( \begin{array}{ccc} ax & 0 & u_0 \\ 0 & ay & v_0 \\ 0 & 0 & 1 \end{array} \right) $

$\endgroup$
4
  • $\begingroup$ Could you please elaborate why you add .5 and then subtract .5? Does 0.5 apply only to scaling w/ a factor $2^n$? If not, how does one compute that sub-pixel number? $\endgroup$ Oct 3, 2014 at 7:07
  • 1
    $\begingroup$ I think the point is that the center of pixel "0, 0" is not really at "0, 0" (=top left corner of the pixel) but at "0.5, 0.5". So you have to account for that offset before and after the transformation, and the factor is always 0.5, no matter the scaling factor. $\endgroup$
    – Jan Rüegg
    Feb 2, 2017 at 8:36
  • $\begingroup$ Yup thats exactly right $\endgroup$
    – Hammer
    Feb 2, 2017 at 20:40
  • $\begingroup$ why does this not decompose into the matrix [0.5ax 0 0.5u0] [0 0.5ay 0.5v0] [0 0 1] when you substitute n = -1 as in Andrey example? $\endgroup$
    – simplename
    Dec 21, 2021 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.