Operator Reference

point_line_to_hom_mat2dT_point_line_to_hom_mat2dPointLineToHomMat2dPointLineToHomMat2dpoint_line_to_hom_mat2d (Operator)

point_line_to_hom_mat2dT_point_line_to_hom_mat2dPointLineToHomMat2dPointLineToHomMat2dpoint_line_to_hom_mat2d — Approximate an affine transformation from point-to-line correspondences.

Signature

point_line_to_hom_mat2d( : : TransformationType, Px, Py, L1x, L1y, L2x, L2y : HomMat2D)

Herror T_point_line_to_hom_mat2d(const Htuple TransformationType, const Htuple Px, const Htuple Py, const Htuple L1x, const Htuple L1y, const Htuple L2x, const Htuple L2y, Htuple* HomMat2D)

void PointLineToHomMat2d(const HTuple& TransformationType, const HTuple& Px, const HTuple& Py, const HTuple& L1x, const HTuple& L1y, const HTuple& L2x, const HTuple& L2y, HTuple* HomMat2D)

void HHomMat2D::PointLineToHomMat2d(const HString& TransformationType, const HTuple& Px, const HTuple& Py, const HTuple& L1x, const HTuple& L1y, const HTuple& L2x, const HTuple& L2y)

void HHomMat2D::PointLineToHomMat2d(const char* TransformationType, const HTuple& Px, const HTuple& Py, const HTuple& L1x, const HTuple& L1y, const HTuple& L2x, const HTuple& L2y)

void HHomMat2D::PointLineToHomMat2d(const wchar_t* TransformationType, const HTuple& Px, const HTuple& Py, const HTuple& L1x, const HTuple& L1y, const HTuple& L2x, const HTuple& L2y)   ( Windows only)

static void HOperatorSet.PointLineToHomMat2d(HTuple transformationType, HTuple px, HTuple py, HTuple l1x, HTuple l1y, HTuple l2x, HTuple l2y, out HTuple homMat2D)

void HHomMat2D.PointLineToHomMat2d(string transformationType, HTuple px, HTuple py, HTuple l1x, HTuple l1y, HTuple l2x, HTuple l2y)

def point_line_to_hom_mat2d(transformation_type: str, px: Sequence[float], py: Sequence[float], l1x: Sequence[float], l1y: Sequence[float], l2x: Sequence[float], l2y: Sequence[float]) -> Sequence[float]

Description

point_line_to_hom_mat2dpoint_line_to_hom_mat2dPointLineToHomMat2dPointLineToHomMat2dpoint_line_to_hom_mat2d approximates an affine transformation from point-to-line correspondences and returns it as the homogeneous transformation matrix HomMat2DHomMat2DHomMat2DhomMat2Dhom_mat_2d (see hom_mat2d_to_affine_parhom_mat2d_to_affine_parHomMat2dToAffineParHomMat2dToAffineParhom_mat2d_to_affine_par for the content of the homogeneous transformation matrix).

The points are passed in the tuples (PxPxPxpxpx,PyPyPypypy). Their corresponding lines are specified as two points on the line, which are passed in (L1xL1xL1xl1xl1x,L1yL1yL1yl1yl1y) and (L2xL2xL2xl2xl2x,L2yL2yL2yl2yl2y). Corresponding points and lines must be at the same index positions in these tuples.

The type of transformation to be approximated is determined with TransformationTypeTransformationTypeTransformationTypetransformationTypetransformation_type. Each type of transformation requires a certain minimum number of point-to-line correspondences, as described in the following table:

TransformationTypeTransformationTypeTransformationTypetransformationTypetransformation_type Type of transformation Minimum number of correspondences
'translation'"translation""translation""translation""translation" translation 2
'rigid'"rigid""rigid""rigid""rigid" rigid transformation 3
'similarity'"similarity""similarity""similarity""similarity" similarity transformation 4
'aniso'"aniso""aniso""aniso""aniso" anisotropic similarity transformation 5
'affine'"affine""affine""affine""affine" general affine transformation 6

The types of transformations that are supported can be described as follows:

'translation':
A translation, i.e., a transformation that can be obtained as follows:

This means that where is the translation vector.

'rigid':

A rigid transformation, i.e., a transformation that can be obtained as follows:

This means that where is a rotation matrix corresponding to the rotation angle Phi and is the translation vector.

'similarity':
A similarity transformation, i.e., a transformation that can be obtained as follows (note the identical scale factors in hom_mat2d_scalehom_mat2d_scaleHomMat2dScaleHomMat2dScalehom_mat2d_scale):
hom_mat2d_identity(HomMat2D)hom_mat2d_identity(HomMat2D)HomMat2dIdentity(HomMat2D)HomMat2dIdentity(HomMat2D)hom_mat2d_identity(HomMat2D)
hom_mat2d_scale(HomMat2D, S, S, 0, 0, HomMat2D)hom_mat2d_scale(HomMat2D, S, S, 0, 0, HomMat2D)HomMat2dScale(HomMat2D, S, S, 0, 0, HomMat2D)HomMat2dScale(HomMat2D, S, S, 0, 0, HomMat2D)hom_mat2d_scale(HomMat2D, S, S, 0, 0, HomMat2D)
hom_mat2d_rotate(HomMat2D, Phi, 0, 0, HomMat2D)hom_mat2d_rotate(HomMat2D, Phi, 0, 0, HomMat2D)HomMat2dRotate(HomMat2D, Phi, 0, 0, HomMat2D)HomMat2dRotate(HomMat2D, Phi, 0, 0, HomMat2D)hom_mat2d_rotate(HomMat2D, Phi, 0, 0, HomMat2D)
hom_mat2d_translate(HomMat2D, Tx, Ty, HomMat2D)hom_mat2d_translate(HomMat2D, Tx, Ty, HomMat2D)HomMat2dTranslate(HomMat2D, Tx, Ty, HomMat2D)HomMat2dTranslate(HomMat2D, Tx, Ty, HomMat2D)hom_mat2d_translate(HomMat2D, Tx, Ty, HomMat2D)
This means that where is a scaling matrix with identical scaling S in the x and y directions, is a rotation matrix corresponding to the rotation angle Phi, and is the translation vector.
'aniso':
An anisotropic similarity transformation, i.e., a transformation that can be obtained as follows (note the different scale factors in hom_mat2d_scalehom_mat2d_scaleHomMat2dScaleHomMat2dScalehom_mat2d_scale):
hom_mat2d_identity(HomMat2D)hom_mat2d_identity(HomMat2D)HomMat2dIdentity(HomMat2D)HomMat2dIdentity(HomMat2D)hom_mat2d_identity(HomMat2D)
hom_mat2d_scale(HomMat2D, Sx, Sy, 0, 0, HomMat2D)hom_mat2d_scale(HomMat2D, Sx, Sy, 0, 0, HomMat2D)HomMat2dScale(HomMat2D, Sx, Sy, 0, 0, HomMat2D)HomMat2dScale(HomMat2D, Sx, Sy, 0, 0, HomMat2D)hom_mat2d_scale(HomMat2D, Sx, Sy, 0, 0, HomMat2D)
hom_mat2d_rotate(HomMat2D, Phi, 0, 0, HomMat2D)hom_mat2d_rotate(HomMat2D, Phi, 0, 0, HomMat2D)HomMat2dRotate(HomMat2D, Phi, 0, 0, HomMat2D)HomMat2dRotate(HomMat2D, Phi, 0, 0, HomMat2D)hom_mat2d_rotate(HomMat2D, Phi, 0, 0, HomMat2D)
hom_mat2d_translate(HomMat2D, Tx, Ty, HomMat2D)hom_mat2d_translate(HomMat2D, Tx, Ty, HomMat2D)HomMat2dTranslate(HomMat2D, Tx, Ty, HomMat2D)HomMat2dTranslate(HomMat2D, Tx, Ty, HomMat2D)hom_mat2d_translate(HomMat2D, Tx, Ty, HomMat2D)
This means that where is a scaling matrix with non-identical scaling Sx and Sy in the x and y directions, is a rotation matrix corresponding to the rotation angle Phi, and is the translation vector.
'affine':
A general affine transformation, i.e., a transformation that can be obtained as follows:
hom_mat2d_identity(HomMat2D)hom_mat2d_identity(HomMat2D)HomMat2dIdentity(HomMat2D)HomMat2dIdentity(HomMat2D)hom_mat2d_identity(HomMat2D)
hom_mat2d_scale(HomMat2D, Sx, Sy, 0, 0, HomMat2D)hom_mat2d_scale(HomMat2D, Sx, Sy, 0, 0, HomMat2D)HomMat2dScale(HomMat2D, Sx, Sy, 0, 0, HomMat2D)HomMat2dScale(HomMat2D, Sx, Sy, 0, 0, HomMat2D)hom_mat2d_scale(HomMat2D, Sx, Sy, 0, 0, HomMat2D)
hom_mat2d_slant(HomMat2D, Theta, 'y', 0, 0, HomMat2D)hom_mat2d_slant(HomMat2D, Theta, "y", 0, 0, HomMat2D)HomMat2dSlant(HomMat2D, Theta, "y", 0, 0, HomMat2D)HomMat2dSlant(HomMat2D, Theta, "y", 0, 0, HomMat2D)hom_mat2d_slant(HomMat2D, Theta, "y", 0, 0, HomMat2D)
hom_mat2d_rotate(HomMat2D, Phi, 0, 0, HomMat2D)hom_mat2d_rotate(HomMat2D, Phi, 0, 0, HomMat2D)HomMat2dRotate(HomMat2D, Phi, 0, 0, HomMat2D)HomMat2dRotate(HomMat2D, Phi, 0, 0, HomMat2D)hom_mat2d_rotate(HomMat2D, Phi, 0, 0, HomMat2D)
hom_mat2d_translate(HomMat2D, Tx, Ty, HomMat2D)hom_mat2d_translate(HomMat2D, Tx, Ty, HomMat2D)HomMat2dTranslate(HomMat2D, Tx, Ty, HomMat2D)HomMat2dTranslate(HomMat2D, Tx, Ty, HomMat2D)hom_mat2d_translate(HomMat2D, Tx, Ty, HomMat2D)
This means that where are arbitrary numbers.

The transformation is computed by minimizing the sum of the squared distances of the points (PxPxPxpxpx,PyPyPypypy) transformed with the computed transformation to the lines given by (L1xL1xL1xl1xl1x,L1yL1yL1yl1yl1y) and (L2xL2xL2xl2xl2x,L2yL2yL2yl2yl2y). The lines are regarded as lines with infinite extent. This means that the points (PxPxPxpxpx,PyPyPypypy) transformed with the transformation HomMat2DHomMat2DHomMat2DhomMat2Dhom_mat_2d may not lie “between” (L1xL1xL1xl1xl1x,L1yL1yL1yl1yl1y) and (L2xL2xL2xl2xl2x,L2yL2yL2yl2yl2y). An exception to this rule occurs for rigid and anisotropic similarity transformations that are determined from the minimum number of point-to-line correspondences (3 and 5, respectively). In this case, there are in general two possible solutions that both yield an error of 0. The algorithm returns the solution for which the transformed points lie as close as possible to the line segments given by (L1xL1xL1xl1xl1x,L1yL1yL1yl1yl1y) and (L2xL2xL2xl2xl2x,L2yL2yL2yl2yl2y). If a unique solution is desired, one additional point-to-line correspondence should be used (i.e., 4 or 6, respectively).

HomMat2DHomMat2DHomMat2DhomMat2Dhom_mat_2d can be used directly with operators that transform data using affine transformations, e.g., affine_trans_imageaffine_trans_imageAffineTransImageAffineTransImageaffine_trans_image.

Attention

It should be noted that homogeneous transformation matrices refer to a general right-handed mathematical coordinate system. If a homogeneous transformation matrix is used to transform images, regions, XLD contours, or any other data that has been extracted from images, the row coordinates of the transformation must be passed in the x coordinates, while the column coordinates must be passed in the y coordinates. Consequently, the order of passing row and column coordinates follows the usual order (RowRowRowrowrow,ColumnColumnColumncolumncolumn). This convention is essential to obtain a right-handed coordinate system for the transformation of iconic data, and consequently to ensure in particular that rotations are performed in the correct mathematical direction.

Furthermore, it should be noted that if a homogeneous transformation matrix is used to transform images, regions, XLD contours, or any other data that has been extracted from images, it is assumed that the origin of the coordinate system of the homogeneous transformation matrix lies in the upper left corner of a pixel. The image processing operators that return point coordinates, however, assume a coordinate system in which the origin lies in the center of a pixel. Therefore, to obtain a consistent homogeneous transformation matrix, 0.5 must be added to the point coordinates before computing the transformation.

Execution Information

  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).
  • Multithreading scope: global (may be called from any thread).
  • Processed without parallelization.

Parameters

TransformationTypeTransformationTypeTransformationTypetransformationTypetransformation_type (input_control)  string HTuplestrHTupleHtuple (string) (string) (HString) (char*)

Type of the transformation to compute.

Default: 'rigid' "rigid" "rigid" "rigid" "rigid"

List of values: 'affine'"affine""affine""affine""affine", 'aniso'"aniso""aniso""aniso""aniso", 'rigid'"rigid""rigid""rigid""rigid", 'similarity'"similarity""similarity""similarity""similarity", 'translation'"translation""translation""translation""translation"

PxPxPxpxpx (input_control)  point.x-array HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)

X coordinates of the original points.

PyPyPypypy (input_control)  point.y-array HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)

Y coordinates of the original points.

L1xL1xL1xl1xl1x (input_control)  point.x-array HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)

X coordinates of the first point on the corresponding line.

L1yL1yL1yl1yl1y (input_control)  point.y-array HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)

Y coordinates of the first point on the corresponding line.

L2xL2xL2xl2xl2x (input_control)  point.x-array HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)

X coordinates of the second point on the corresponding line.

L2yL2yL2yl2yl2y (input_control)  point.y-array HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)

Y coordinates of the second point on the corresponding line.

HomMat2DHomMat2DHomMat2DhomMat2Dhom_mat_2d (output_control)  hom_mat2d HHomMat2D, HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)

Output transformation matrix.

Example (HDevelop)

* Use point_line_to_hom_mat2d for alignment.
* Read the reference image.
read_image (Image, ReferenceFileName)
* Set up the metrology model with four lines.  Four lines are used
* since this is the minimum number of point-to-line correspondences
* that results in a unique rigid transformation.
Row1 := [RowB1,RowB2,RowB3,RowB4]
Col1 := [ColB1,ColB2,ColB3,ColB4]
Row2 := [RowE1,RowE2,RowE3,RowE4]
Col2 := [ColE1,ColE2,ColE3,ColE4]
create_metrology_model (MetrologyHandle)
add_metrology_object_line_measure (MetrologyHandle, Row1, Col1, \
                                   Row2, Col2, 40, 5, 1, 30, \
                                   [], [], Index)
* Apply the metrology model to the reference image and read out
* the results.
apply_metrology_model (Image, MetrologyHandle)
get_metrology_object_result (MetrologyHandle, 'all', 'all', \
                             'result_type', 'row_begin', \
                             RowBegin)
get_metrology_object_result (MetrologyHandle, 'all', 'all', \
                             'result_type', 'column_begin', \
                             ColBegin)
get_metrology_object_result (MetrologyHandle, 'all', 'all', \
                             'result_type', 'row_end', \
                             RowEnd)
get_metrology_object_result (MetrologyHandle, 'all', 'all', \
                             'result_type', 'column_end', \
                             ColEnd)
* The reference points of the model are the center points of the
* detected line segments.  They will be used to compute the
* transformation from the current image to the reference image
* using point_line_to_hom_mat2d below.
RowRef := 0.5*(RowBegin+RowEnd)
ColRef := 0.5*(ColBegin+ColEnd)
for I := 1 to |FileNames|-1 by 1
    read_image (Image, FileNames[I])
    * Apply the metrology model to the current image and read out
    * the line segment coordinates.
    apply_metrology_model (Image, MetrologyHandle)
    get_metrology_object_result (MetrologyHandle, 'all', 'all', \
                                 'result_type', 'row_begin', \
                                 RowBegin)
    get_metrology_object_result (MetrologyHandle, 'all', 'all', \
                                 'result_type', 'column_begin', \
                                 ColBegin)
    get_metrology_object_result (MetrologyHandle, 'all', 'all', \
                                 'result_type', 'row_end', \
                                 RowEnd)
    get_metrology_object_result (MetrologyHandle, 'all', 'all', \
                                 'result_type', 'column_end', \
                                 ColEnd)
    * Determine a rigid transformation based on the point-to-line
    * correspondences from the reference points to the extracted
    * lines.  Note that this determines a transformation from the
    * reference points to the lines in the current image.
    * Therefore, we must invert this transformation to obtain the
    * transformation from the current image to the rerefence image.
    point_line_to_hom_mat2d ('rigid', RowRef+0.5, ColRef+0.5, \
                             RowBegin+0.5, ColBegin+0.5, \
                             RowEnd+0.5, ColEnd+0.5, HomMat2D)
    hom_mat2d_invert (HomMat2D, HomMat2DInvert)
    affine_trans_image (Image, ImageTrans, HomMat2DInvert, \
                        'constant', 'false')
    * Now that the current image has been aligned with the
    * reference image, we can do some processing based on the
    * aligned image ImageTrans.
    * [...]
endfor

Possible Successors

affine_trans_imageaffine_trans_imageAffineTransImageAffineTransImageaffine_trans_image, affine_trans_image_sizeaffine_trans_image_sizeAffineTransImageSizeAffineTransImageSizeaffine_trans_image_size, affine_trans_regionaffine_trans_regionAffineTransRegionAffineTransRegionaffine_trans_region, affine_trans_contour_xldaffine_trans_contour_xldAffineTransContourXldAffineTransContourXldaffine_trans_contour_xld, affine_trans_polygon_xldaffine_trans_polygon_xldAffineTransPolygonXldAffineTransPolygonXldaffine_trans_polygon_xld, affine_trans_point_2daffine_trans_point_2dAffineTransPoint2dAffineTransPoint2daffine_trans_point_2d

See also

vector_to_hom_mat2dvector_to_hom_mat2dVectorToHomMat2dVectorToHomMat2dvector_to_hom_mat2d, vector_to_anisovector_to_anisoVectorToAnisoVectorToAnisovector_to_aniso, vector_to_similarityvector_to_similarityVectorToSimilarityVectorToSimilarityvector_to_similarity, vector_to_rigidvector_to_rigidVectorToRigidVectorToRigidvector_to_rigid

Module

Foundation