ABC Transform#

Transform Class#

class Transform(parameters=None, constants=None)[source]#

Abstract base class representing a parametric transformation that maps points from an input space to an output space.

A transformation maps points \(\vec{X}_I \in \mathbb{R}^{\text{input dim}}\) to points \(\vec{X}_O \in \mathbb{R}^{\text{output dim}}\):

\[\vec{X}_O = T(\vec{X}_I, \lambda_1, \lambda_2, \ldots, \lambda_{n_{\text{params}}})\]

where \(\vec{X}_I\) are the input points, \(\vec{X}_O\) are the output points, and \(\{\lambda_i\}\) are the parameters of the transformation.

A transformation is defined by:

  • a set of n_params parameters that define the transformation and may be optimized,

  • a set of n_constants constants that remain fixed and are not part of the optimization variables (no Jacobian is computed with respect to these constants).

This class defines the common interface for all transformations used in pycvcam. Typical subclasses include:

Methods to implement#

Subclasses must implement the following methods and properties:

  • _transform (method):

    Apply the transformation to points of shape (..., input_dim) and return the transformed points of shape (..., output_dim). Jacobian matrices may optionally be returned.

  • _inverse_transform (method):

    Apply the inverse transformation to points of shape (..., output_dim) and return the transformed points of shape (..., input_dim). Jacobian matrices may optionally be returned.

  • input_dim (property):

    Dimension of the input points (e.g. 2 for 2D points).

  • output_dim (property):

    Dimension of the output points.

  • n_params (property):

    Number of parameters of the transformation.

  • n_constants (property):

    Number of constants of the transformation.

The following attributes and methods are optional and may be overridden to provide additional information about the transformation:

  • parameters (property and setter):

    Parameters of the transformation as a 1D numpy array of shape (n_params,). If the transformation has no parameters the array has shape (0,). If parameters are not yet initialized, the value may be None. For a zero-parameter transformation, this property should return an empty array of shape (0,) instead of None.

  • constants (property and setter):

    Constants of the transformation as a 1D numpy array of shape (n_constants,). If the transformation has no constants the array has shape (0,). If constants are not yet initialized, the value may be None. For a zero-constant transformation, this property should return an empty array of shape (0,) instead of None.

  • parameter_names (property):

    Names of the parameters as a list of strings. The default is [p_0, p_1, ..., p_{n_params-1}].

  • constant_names (property):

    Names of the constants as a list of strings. The default is [c_0, c_1, ..., c_{n_constants-1}].

  • is_set (method):

    Returns whether the transformation parameters and constants have been initialized.

  • _result_class (class attribute):

    Class used to represent the result of the transformation. Must be a subclass of pycvcam.TransformResult.

  • _inverse_result_class (class attribute):

    Class used to represent the result of the inverse transformation.

  • _get_jacobian_shorthands (method):

    Dictionary defining shorthand notations for views of the Jacobian matrix with respect to parameters.

  • _get_transform_aliases (method):

    Dictionary defining aliases for parameter names in the forward transformation.

  • _get_inverse_transform_aliases (method):

    Dictionary defining aliases for parameter names in the inverse transformation.

More details on the transformation interface are provided in the pycvcam.Transform.transform() and pycvcam.Transform.inverse_transform() methods.

Parameters:
  • parameters (Optional[ArrayLike])

  • constants (Optional[ArrayLike])

Public Methods of Transform subclasses#

Transformation caracteristics#

To have informations on the transformation caracteristics, use the following methods:

Transform.input_dim

[Get] the input dimension of the transformation.

Transform.output_dim

[Get] the output dimension of the transformation.

Transform.parameters

[Get/Set] the parameters of the transformation.

Transform.n_params

[Get] the number of parameters of the transformation.

Transform.parameter_names

[Get] the names of the parameters of the transformation.

Transform.constants

[Get/Set] to return the constants of the transformation.

Transform.n_constants

[Get] the number of constants of the transformation.

Transform.constant_names

[Get] the names of the constants of the transformation.

Transform.__repr__()

String representation of the Transform class.

Transforming Points#

To transform points using the transformation from \(\mathbb{R}^{\text{input dim}}\) to \(\mathbb{R}^{\text{output dim}}\), use the following method:

Transform.transform(points, *[, transpose, ...])

Apply the transformation to the given points from input space to output space.

Transform.inverse_transform(points, *[, ...])

Apply the inverse transformation to the given points, mapping output space back to input space.

Save and Load Transformations#

To save and load transformations, use the following methods:

Transform.copy()

Return a deep copy of the transformation.

Transform.to_dict()

Serialize the transformation to a dictionary.

Transform.from_dict(data)

Create a Transform object from a dictionary.

Transform.to_json(filepath)

Write the transformation to a JSON file.

Transform.from_json(filepath)

Read a Transform object from a JSON file.