pysdic.BrownDistortion._apply#

BrownDistortion._apply(normalized_points, *, dx=False, dp=False, opencv=False)[source]#

Compute the transformation from the normalized points to the distorted points.

The distortion without tilt \(\vec{x}_0\) is given by the OpenCV model (see the class documentation). Its Jacobian with respect to the normalized points is, with \(K' = \frac{dK}{d(r^2)}\):

\[\begin{split}\frac{\partial \vec{x}_0}{\partial \vec{x}_n} = \begin{bmatrix} K + 2 x_n^2 K' + 2 p_1 y_n + 6 p_2 x_n + 2 x_n (s_1 + 2 s_2 r^2) & 2 x_n y_n K' + 2 p_1 x_n + 2 p_2 y_n + 2 y_n (s_1 + 2 s_2 r^2) \\ 2 x_n y_n K' + 2 p_1 x_n + 2 p_2 y_n + 2 x_n (s_3 + 2 s_4 r^2) & K + 2 y_n^2 K' + 6 p_1 y_n + 2 p_2 x_n + 2 y_n (s_3 + 2 s_4 r^2) \end{bmatrix}\end{split}\]

and its Jacobian with respect to the coefficients is obtained by direct differentiation, for example \(\frac{\partial x_0}{\partial k_1} = x_n \frac{r^2}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6}\) and \(\frac{\partial x_0}{\partial k_4} = - x_n K \frac{r^2}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6}\).

With the tilt parameters, the Jacobians are multiplied by the Jacobian of the projection \(\vec{x}_0 \mapsto \vec{x}_d\):

\[\begin{split}\frac{\partial \vec{x}_d}{\partial \vec{x}_0} = \frac{1}{h_z} \begin{bmatrix} M_{00} - x_d M_{20} & M_{01} - x_d M_{21} \\ M_{10} - y_d M_{20} & M_{11} - y_d M_{21} \end{bmatrix}\end{split}\]

and the columns of the tilt parameters are \(\frac{\partial \vec{x}_d}{\partial \tau} = \frac{1}{h_z} \left( \vec{h}'_{xy} - \vec{x}_d h'_z \right)\) with \(\vec{h}' = \frac{\partial M}{\partial \tau} (x_0, y_0, 1)^T\).

To compute the distortion with OpenCV (cv2.projectPoints), set opencv=True. In this case, the Jacobian dx is not available.

Parameters:
  • normalized_points (numpy.ndarray) – The normalized points. Shape (n_points, 2).

  • dx (bool, optional (default: False)) – If True, the Jacobian with respect to the normalized points is computed.

  • dp (bool, optional (default: False)) – If True, the Jacobian with respect to the distortion parameters is computed.

  • opencv (bool, optional (default: False)) – If True, the distortion is computed with the OpenCV function projectPoints.

Returns:

  • distorted_points (numpy.ndarray) – The distorted points. Shape (n_points, 2).

  • jacobian_dx (Optional[numpy.ndarray]) – The Jacobian of the distorted points with respect to the normalized points. Shape (n_points, 2, 2) if dx=True, otherwise None.

  • jacobian_dp (Optional[numpy.ndarray]) – The Jacobian of the distorted points with respect to the distortion parameters. Shape (n_points, 2, N) if dp=True, otherwise None.

Return type:

Tuple[ndarray, ndarray | None, ndarray | None]