Transformation matrix
lastmod 2024-02-21created 2017-11-098 edits
Transformation matrices In linear algebra, linear transformations can be represented by matrices. Historically, various ways of expressing the transformation (or deformation) of matrices on matrices have also been studied.
Category
- Rigid Transformation
- A Rigid Transform keeps the shape and applies rotation and translation
- A rigid transformation can be computed from just 2 motion vectors. In other words, since it is computed from 2 coordinate points, you can think of the transformation as constrained. The key point is that the shape does not change. That is, a square must stay a square.
- Similarity Transformation
- A similarity transformation is a rigid transformation that additionally allows a change of scale
- Affine Transformation
- An affine transformation preserves straight lines, ratios of lengths (distances), and parallelism.
- Homography (Projective Transformation)
- Homography Transform: Projection Transform
- A transformation that includes shape, rotation, rotation, and translation altogether
OpenCV methods
A summary of the OpenCV functions related to 2D transformations.
-
estimateRigidTransform() - Used to compute a similarity or affine transformation from many matching pairs (selectable by parameter). Uses RANSAC internally.
-
opencv2/video/video.hpp
-
getAffineTransform() - Computes an affine transformation from 3 input matching pairs.
-
opencv2/imgproc/imgproc.hpp
-
invertAffineTransform() - Computes the inverse of an affine transformation.
-
opencv2/imgproc/imgproc.hpp
-
getPerspectiveTransform() - Computes a homography matrix from 4 input matching pairs.
-
opencv2/imgproc/imgproc.hpp
-
findHomography() - Computes a homography matrix from many matching pairs (approximation method chosen from fitting all data, RANSAC, or LMedS).
-
opencv2/calib3d/calib3d.hpp
-
transform() - Used to transform coordinates with a 2×2 or 2×3 transformation matrix (similarity, affine, etc.).
-
perspectiveTransform() - Used to transform coordinates with a 3x3 homography matrix or a 4×4 transformation matrix.
Scaling matrix
When scaling each axis, the following formulas hold.
-
x' = ax -
y' = by -
z' = cz
Expressed as a matrix, this becomes:
Size_matrix.gif
Rotation matrix
Deriving the rotation matrix In linear algebra, a rotation matrix is a matrix that is used to perform a rotation in Euclidean space.
A general term for matrices used for rotation.
In two dimensions
In two dimensions, every rotation matrix has the following form,
Positive_rotation_matrix.png
The direction of vector rotation is counterclockwise if θ is positive (e.g. 90°), and clockwise if θ is negative (e.g. −90°). Thus the clockwise rotation matrix is found as
Negative_rotation_matrix.png
Derivation
The derivation is as follows.
As in (a) of the figure on the right, suppose an object is at point A with coordinates (x, y) relative to the camera. If the camera rotates left by θ=30°, the same object appears at coordinates (x', y'). Here x' and y' are determined by the original coordinates and the angle θ. Looking closely at (b) of the figure, you can see that the following relations hold.
-
x' = xcosθ - ysinθ -
y' = xsinθ + ycosθ
If θ is in the negative direction (clockwise), the rotation matrix must be changed as follows.
-
x' = xcosθ + ysinθ -
y' = -xsinθ + ycosθ
This is the same as a rotation about the z axis (the direction going into and out of the plane). Expressed as a matrix:
Rotation_matrix_3d_z.gif
In the same way, the matrices for rotation about the x and y axes are:
Rotation_matrix_3d_xy.gif
For the exact derivation, see this2.