pysdic.ZernikeDistortion._invert#

ZernikeDistortion._invert(distorted_points, *, dx=False, dp=False, max_iteration=50, tolerance=1e-14, pysolvegn=False, solve_kwargs=None)[source]#

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

The normalized points \(\vec{x}_n\) are the solutions of \(D(\vec{x}_n) = \vec{x}_d\), where \(D\) is the distortion. They are computed with Newton iterations, starting from \(\vec{x}_n^{(0)} = 2 \vec{x}_d - D(\vec{x}_d)\):

\[\vec{x}_n^{(k+1)} = \vec{x}_n^{(k)} - \left(\frac{\partial D}{\partial \vec{x}_n}(\vec{x}_n^{(k)})\right)^{-1} \left( D(\vec{x}_n^{(k)}) - \vec{x}_d \right)\]

until the update of every point is below tolerance (relatively to the magnitude of the point).

The Jacobians are obtained by differentiating the identity \(D(D^{-1}(\vec{x}_d; \vec{p}); \vec{p}) = \vec{x}_d\):

\[\frac{\partial D^{-1}}{\partial \vec{x}_d} = \left( \frac{\partial D}{\partial \vec{x}_n}(\vec{x}_n) \right)^{-1}, \qquad \frac{\partial D^{-1}}{\partial \vec{p}} = - \frac{\partial D^{-1}}{\partial \vec{x}_d} \cdot \frac{\partial D}{\partial \vec{p}}(\vec{x}_n)\]

To solve the undistortion with pysolvegn (for example with a Levenberg-Marquardt damping), set pysolvegn=True and give the options of the solver with solve_kwargs. In this case, the Jacobians are not available.

Note

A RuntimeWarning is emitted if some points do not converge within max_iteration iterations, which usually means that the points are outside the ellipse of definition or outside the domain where the distortion is bijective.

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

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

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

  • max_iteration (int, optional (default: 50)) – The maximum number of Newton iterations.

  • tolerance (float, optional (default: 1e-14)) – The relative tolerance on the update of the points to stop the iterations.

  • pysolvegn (bool, optional (default: False)) – If True, the undistortion is computed with pysdic.optimize_transformation_input_points() (pysolvegn.solve_batch) instead of the Newton iterations, starting from the same initial guess. In this case, the Jacobians are not available.

  • solve_kwargs (Optional[Dict[str, Any]], optional (default: None)) – Only with pysolvegn=True: additional keyword arguments passed to pysolvegn.solve_batch (damping, verbosity, …) or to pysdic.optimize_transformation_input_points() (mode, loss, loss_scale). By default, max_iteration=max_iteration and xtol=tolerance.

Returns:

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

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

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

Return type:

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