Thursday, January 30, 2020

matlab - How does resizing an image affect the intrinsic camera matrix?


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.



Answer



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.


No comments:

Post a Comment

digital communications - Understanding the Matched Filter

I have a question about matched filtering. Does the matched filter maximise the SNR at the moment of decision only? As far as I understand, ...