dvpio.read.shapes.transform_shapes

dvpio.read.shapes.transform_shapes#

dvpio.read.shapes.transform_shapes(shapes, calibration_points_target, calibration_points_source, *, precision=None, transformation_type='similarity')#

Apply coordinate transformation to shapes based on calibration points from a target and a source

Computes transformation between source and target coordinates.

Parameters:
  • shapes (ShapesModel) – Shapes in source coordinate system (usually LMD coordinates)

  • calibration_points_target (PointsModel) – 3 Calibration points in target coordinate system (usually image/pixel coordinates) Expects spatialdata.models.PointsModel with calibration points in x/y column

  • calibration_points_source (PointsModel) – 3 Calibration points, matched to calibration_points_target in source coordinate system (usually LMD coordinates) Expects spatialdata.models.PointsModel with calibration points in x/y column

  • transformation_type (Literal['similarity', 'affine', 'euclidean'] (default: 'similarity')) –

    • affine

      Full affine transformation (scaling, rotation/reflexion, translation, shearing). This operation does not preserve the angles within or distances the shapes

    • similarity (recommended)

      Similarity transformation. Compared to an affine transformation, a similarity transformation constraints the solution space to scaling, rotations, reflections, and translations, i.e. angles of shapes are retained. If you only want to map between image and microscopy coordinates only the subset of similarity transformations (scaling, rotation, reflection, translation) is required.

    • euclidean (Rigid transform)

      Only translation and rotation are allowed

  • precision (Optional[int] (default: None)) – Rounding digit of affine transformation matrix. Small values (~6) might be necessary for numerical stability of shape transformations.

Return type:

ShapesModel

Returns:

spatialdata.models.ShapesModel

Transformed shapes in target coordinate system

Object has special attributes

  • attrs.transformation
    • global: (image coordinates)

    • to_lmd: Leica coordinate system transformation

Raises:

AttributeError – Checks validity of shapes and calibration points data formats