To specify a location in an image, we need a convention how to do so. Such a convention is set via a coordinate system. There are different coordinate systems used in HALCON. Here, we explain the ones used in 2D.
Pixels are discrete and to address them, we have a coordinate system using only integer values, the pixel coordinate system. For a higher accuracy that goes beyond the pixel grid, we need floating point coordinates, like e.g., . This leads to subpixel accurate coordinate systems. In HALCON, we have three different implementations of subpixel coordinate systems:
Pixel Centered Coordinates, the HALCON Standard Subpixel Coordinate System
Edge Centered Coordinates
Polar Coordinates
Thereof the first two vary only in the coordinate origin,
as visible in the figures below.
Calibration makes it possible to map the image coordinates distances to
real-world distances. For more information about these Calibrated
Coordinates we refer to the “Solution Guide III-C - 3D Vision”
.
The pixel coordinate system treats the image as a grid of discrete elements, the pixels. In HALCON, we put the origin in the middle of the upper left pixel. Now, we assign the pixel coordinates specifying its row and column like in a matrix.
Note that this implies for an image of size height width = pixels that the row coordinate values run from to and the column coordinate values from to , as visualized in the figure below.
The origin of this coordinate system is in the center of the upper left image pixel, the axes are in row (r) and column (c) direction, respectively. Therewith this convention embeds the pixel coordinate system. The upper left image corner has the coordinates and for an image of size height width = pixels the bottom right corner has the coordinates (=, remember the coordinate values start at 0). It also implies that a pixel (k,l) covers the area of the rectangle , , , . This convention is called the standard coordinate system, or also Image Coordinate System.
( 1) | ( 2) |
If we rotate an image around its origin by (=90 degrees), we want the two images with touching edges but not overlapping with each other. Also, scaling the image is not expected to result in negative image coordinates. For this, the origin has to be set in an image corner. This motivates the following coordinate system.
For this coordinate system we set the origin in the upper left image corner. Thus the center of the upper left pixel has the coordinates and for an image of size height width = pixels the bottom right corner has the coordinates . A pixel covers the area of the rectangle , , , .
For this coordinate system rotations are defined in the mathematically positive direction and thus counterclockwise. A rotation of (=90 degrees) maps the first axis (= x-axis) onto the second axis (= y-axis). Accordingly, the axes have the assignment row: x coordinate, column: y coordinate.
The operator
applies the transformation
given by affine_trans_point_2d
to the point coordinates.
This means, HomMat2D
works
in both Cartesian Coordinate systems, as long you make sure that the point
and the transformation are given in the same coordinate system.
affine_trans_point_2d
The operators
and angle_ll
may take the input
points in pixel centered coordinates, but the returned angle is in the
convention of rotations in a mathematically positive direction, thus
counterclockwise, and with the horizontal axis as 0, like in the
edge centered coordinate system.
angle_lx
In HALCON there is also the case that an operator expects its input in
different coordinate systems.
On the one hand, the object is expected in its usual coordinates, the
standard coordinates.
On the other hand, for the transformation matrix
, the
operator expects edge centered coordinates with their advantages regarding
transformations described above.
The operator converts the coordinates of the object from HALCON's
standard coordinate system (with the origin in the center of the
upper left pixel) to the edge centered coordinate system
(with the origin in the upper left corner of the upper left pixel).
After the transformation with HomMat2D
, the result is
converted back to the standard coordinate system.
HomMat2D
These operators are
A matrix representing a transformation in pixel centered coordinates can be converted to represent the same transformation (e.g., a rotation around the same point) written in edge centered coordinates, e.g., through
|
|
Note, the operators beginning with projective_
mentioned above
use a projective transformation matrix. These transformation matrices can,
e.g., be obtained from a 3D camera pose. Doing so, the matrix used is
written in a projection of the xy-plane within the 3D coordinate system.
Accordingly, the axes have the assignment row: y coordinate, column:
x coordinate and therewith the coordinates need to be converted.
Results from shape-based matching, like e.g.,
, are given in edge centered coordinates.
The returned matches are already transformed. The respective homographic
transformation matrices can be retrieved using
find_generic_shape_model
.
get_generic_shape_model_result
Results from correlation-based matching, like e.g.,
and find_ncc_model
,
are computed in edge centered coordinates as well, however the parameters
for the transformation are returned separately.
With these results one can create a transformation
find_ncc_models
directly applicable for,
e.g., HomMat2D
and the other operators listed in the paragraph above, entitled
affine_trans_contour_xld
Operators Expecting Parameters in Different Coordinate Systems
.
To display the results found by correlation-based matching, we highly
recommend the usage of the procedure
dev_display_ncc_matching_results
.
In the following images we give an example how a displayed
match may look when using the transformation matrix in the correct and
the erroneous coordinate system, respectively.
For the latter one, shown in image (3), the transition matrix is given in
pixel centered coordinates as well and therefore the match shown by
is off by 0.5 pixels.
Note, this effect is only visible when a rotation is involved.
affine_trans_contour_xld
( 1) | ( 2) | ( 3) |
In polar coordinates, points are defined through a distance and an angle. The distance is called the radial coordinate and is given in relation to the fix point, the pole. The angular coordinate is given with respect to a defined axis, the polar axis. In HALCON, the pole is specified by and the polar axis is the horizontal axis. The angular coordinate is given in radians.
After a transformation with
, the
upper left pixel in the output image always corresponds to the
point in the input image that is specified by polar_trans_image_ext
and RadiusStart
. Analogously, the lower right pixel in the
output image corresponds to the point in the input image that
is specified by AngleStart
and RadiusEnd
. In the
usual mode (AngleEnd
< AngleStart
and
AngleEnd
< RadiusStart
), the polar
transformation is performed in the mathematically positive
orientation (counterclockwise). Furthermore, points with smaller
radius lie in the upper part of the output image. By suitably
exchanging the values of these parameters (e.g., RadiusEnd
> AngleStart
or AngleEnd
>
RadiusStart
), any desired orientation of the output image can
be achieved.
RadiusEnd
( 1) | ( 2) | ( 3) |
Polar coordinates are used by the following operators:
In the part before we spoke about coordinates of images. When it comes to the location of the origin of the coordinate system used, images with reduced domains, regions, and models are treated differently than images.
Both images with a reduced domain and regions keep the coordinate system of the image from which they were created. This means, they inherit the origin and the points keep the coordinate values they had in the original image.
Models, on the other side, can have a local coordinate system.
E.g., models obtained over
have their
origin in the center of gravity of the ROI they are created from.
For further information see the
create_generic_shape_model
“Solution Guide II-B - Matching”
.
While working with pixel units, we can not extract any information about
real-world distances directly.
When a camera is calibrated, it is possible to rectify the images.
In this case one can assign world coordinates to the image.
For further information we refer to the
“Solution Guide III-C - 3D Vision”
.
affine_trans_pixel
affine_trans_point_2d
deserialize_hom_mat2d
hom_mat2d_compose
hom_mat2d_determinant
hom_mat2d_identity
hom_mat2d_invert
hom_mat2d_reflect
hom_mat2d_reflect_local
hom_mat2d_rotate
hom_mat2d_rotate_local
hom_mat2d_scale
hom_mat2d_scale_local
hom_mat2d_slant
hom_mat2d_slant_local
hom_mat2d_to_affine_par
hom_mat2d_translate
hom_mat2d_translate_local
hom_mat2d_transpose
hom_mat3d_project
hom_vector_to_proj_hom_mat2d
point_line_to_hom_mat2d
projective_trans_pixel
projective_trans_point_2d
serialize_hom_mat2d
vector_angle_to_rigid
vector_field_to_hom_mat2d
vector_to_aniso
vector_to_hom_mat2d
vector_to_proj_hom_mat2d
vector_to_proj_hom_mat2d_distortion
vector_to_rigid
vector_to_similarity