point_line_to_hom_mat2dT_point_line_to_hom_mat2dPointLineToHomMat2dPointLineToHomMat2d (Operator)

Name

point_line_to_hom_mat2dT_point_line_to_hom_mat2dPointLineToHomMat2dPointLineToHomMat2d — 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)

Description

point_line_to_hom_mat2dpoint_line_to_hom_mat2dPointLineToHomMat2dPointLineToHomMat2dPointLineToHomMat2d approximates an affine transformation from point-to-line correspondences and returns it as the homogeneous transformation matrix HomMat2DHomMat2DHomMat2DHomMat2DhomMat2D (see hom_mat2d_to_affine_parhom_mat2d_to_affine_parHomMat2dToAffineParHomMat2dToAffineParHomMat2dToAffinePar 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 TransformationTypeTransformationTypeTransformationTypeTransformationTypetransformationType. Each type of transformation requires a certain minimum number of point-to-line correspondences, as described in the following table:

TransformationTypeTransformationTypeTransformationTypeTransformationTypetransformationType Type of transformation Minimum number of correspondences
'translation' translation 2
'rigid' rigid transformation 3
'similarity' similarity transformation 4
'aniso' anisotropic similarity transformation 5
'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: hom_mat2d_identity (HomMat2D) hom_mat2d_translate (HomMat2D, Tx, Ty, HomMat2D) This means that where is the translation vector.

'rigid':

A rigid transformation, i.e., a transformation that can be obtained as follows: hom_mat2d_identity (HomMat2D) hom_mat2d_rotate (HomMat2D, Phi, 0, 0, HomMat2D) hom_mat2d_translate (HomMat2D, Tx, Ty, HomMat2D) 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_scaleHomMat2dScaleHomMat2dScaleHomMat2dScale): hom_mat2d_identity (HomMat2D) hom_mat2d_scale (HomMat2D, S, S, 0, 0, HomMat2D) hom_mat2d_rotate (HomMat2D, Phi, 0, 0, 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_scaleHomMat2dScaleHomMat2dScaleHomMat2dScale): hom_mat2d_identity (HomMat2D) hom_mat2d_scale (HomMat2D, Sx, Sy, 0, 0, HomMat2D) hom_mat2d_rotate (HomMat2D, Phi, 0, 0, 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_scale (HomMat2D, Sx, Sy, 0, 0, HomMat2D) hom_mat2d_slant (HomMat2D, Theta, 'y', 0, 0, HomMat2D) hom_mat2d_rotate (HomMat2D, Phi, 0, 0, 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 HomMat2DHomMat2DHomMat2DHomMat2DhomMat2D 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).

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

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

Parameters

TransformationTypeTransformationTypeTransformationTypeTransformationTypetransformationType (input_control)  string HTupleHTupleHtuple (string) (string) (HString) (char*)

Type of the transformation to compute.

Default value: '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 HTupleHTupleHtuple (real) (double) (double) (double)

X coordinates of the original points.

PyPyPyPypy (input_control)  point.y-array HTupleHTupleHtuple (real) (double) (double) (double)

Y coordinates of the original points.

L1xL1xL1xL1xl1x (input_control)  point.x-array HTupleHTupleHtuple (real) (double) (double) (double)

X coordinates of the first point on the corresponding line.

L1yL1yL1yL1yl1y (input_control)  point.y-array HTupleHTupleHtuple (real) (double) (double) (double)

Y coordinates of the first point on the corresponding line.

L2xL2xL2xL2xl2x (input_control)  point.x-array HTupleHTupleHtuple (real) (double) (double) (double)

X coordinates of the second point on the corresponding line.

L2yL2yL2yL2yl2y (input_control)  point.y-array HTupleHTupleHtuple (real) (double) (double) (double)

Y coordinates of the second point on the corresponding line.

HomMat2DHomMat2DHomMat2DHomMat2DhomMat2D (output_control)  hom_mat2d HHomMat2D, HTupleHTupleHtuple (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_imageAffineTransImageAffineTransImageAffineTransImage, affine_trans_image_sizeaffine_trans_image_sizeAffineTransImageSizeAffineTransImageSizeAffineTransImageSize, affine_trans_regionaffine_trans_regionAffineTransRegionAffineTransRegionAffineTransRegion, affine_trans_contour_xldaffine_trans_contour_xldAffineTransContourXldAffineTransContourXldAffineTransContourXld, affine_trans_polygon_xldaffine_trans_polygon_xldAffineTransPolygonXldAffineTransPolygonXldAffineTransPolygonXld, affine_trans_point_2daffine_trans_point_2dAffineTransPoint2dAffineTransPoint2dAffineTransPoint2d

See also

vector_to_hom_mat2dvector_to_hom_mat2dVectorToHomMat2dVectorToHomMat2dVectorToHomMat2d, vector_to_anisovector_to_anisoVectorToAnisoVectorToAnisoVectorToAniso, vector_to_similarityvector_to_similarityVectorToSimilarityVectorToSimilarityVectorToSimilarity, vector_to_rigidvector_to_rigidVectorToRigidVectorToRigidVectorToRigid

Module

Foundation