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), setpysolvegn=Trueand give the options of the solver withsolve_kwargs. In this case, the Jacobians are not available.Note
A
RuntimeWarningis emitted if some points do not converge withinmax_iterationiterations, 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 withpysdic.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 withpysolvegn=True: additional keyword arguments passed topysolvegn.solve_batch(damping,verbosity, …) or topysdic.optimize_transformation_input_points()(mode,loss,loss_scale). By default,max_iteration=max_iterationandxtol=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)ifdx=True, otherwiseNone.jacobian_dp (Optional[numpy.ndarray]) – The Jacobian of the normalized points with respect to the distortion parameters. Shape
(n_points, 2, n_parameters)ifdp=True, otherwiseNone.
- Return type: