A rotational matrix, a type of matrix used in image processing, can rotate an image by a particular angle.
In this tutorial, we’ll show how to determine the rotation angle from a rotation matrix. We’ll start with the rotation matrix for an angle, and we’ll learn how to calculate that angle.
2. Image Transformations
Transformation is a function that, after executing various operations, maps one set to another set. In computer graphics, transformations are crucial for resizing, rotating, and repositioning the graphics on the screen.
Transforming involves using rules to turn certain graphics into something else. We refer to the transformation as a 2D transformation occurring on a 2D plane. Transformations come in various forms, including translation, rotation, scaling up or down, and shearing.
A translation changes the location of an object on the screen. We can translate a point by including a translation vector with the original coordinates:
We use the scaling transformation to alter an object’s size. We either increase or decrease the object’s dimensions throughout the scaling procedure. We can scale an object by multiplying its original coordinates by the scaling factor:
When rotating an object, we rotate it around the coordinate system’s origin to a specific degree:
The shear transformation is a transformation that tilts an object’s shape. Skewing is another name for shearing transformation. -Shear and -Shear are the two kinds of shear that can be applied to an image. -Shear is shear applied only along the axis:
-Shear is shear applied only along the axis:
One may apply shear to the or coordinates independently or simultaneously to both and coordinates:
3. Image Transformation Matrices
An square matrix serves as a common type of -dimensional transformation matrix. We can represent any transformation performed on a pixel by a two-dimensional transformation matrix, since the coordinates in a picture are only two-dimensional.
3.1. Matrix Representation for Image Coordinates
It is common to represent image coordinates in a matrix. For the current tutorial, we will represent a coordinate as follows:
After applying the transformation, we move the same coordinate to the following coordinate:
Note that in this context, movement is the act of moving a particular pixel data (color and intensity) from one to another position in the image.
3.2. Matrix Representation for Image Transformation
If we subject a pixel to multiple transformations, the result of the previous transformation must serve as the input for the subsequent transformation:
Concatenating multiple transformation matrices results in a combined transformation matrix, which we can use to perform a composite transformation.
3.3. Matrix Representation for Homogeneous Image Coordinates
Instead of using a two-dimensional transformation matrix, we must utilize a three-dimensional transformation matrix to speed up the process of conducting a sequence of transformations. To the two-dimensional pixel coordinate for this, we add a dummy coordinate:
By doing so, we can represent a pixel with three numbers rather than two, a technique known as homogeneous coordinates. In this system, we can use matrix multiplication to describe all transformation equations.
3.4. Matrix Representation for Image Transformation
We can use a single transformation that is the composition of and taken in that order to express the result itself, if a plane transformation is followed by a second plane transformation . We write it as:
4. Affine Image Transformation Matrices
A linear mapping technique that preserves planes, straight lines, and points is known as an affine translation. An affine transformation, also known as an affinity, is a geometric transformation in Euclidean geometry that generally retains parallelism and lines but not always distances and angles.
A linear transform and a translation vector make up an affine transform. For the affine transformations mentioned above, we give transformation matrices in this section.
4.1. Translation Transformation
We can express the image transformation described in earlier sections in matrix form as follows:
The usual translation matrix in a homogeneous coordinate system is shown below:
4.2. Scaling Transformation
We can express the scaling transformation described in earlier sections in matrix form as follows:
The usual scaling matrix in a homogeneous coordinate system is shown below:
4.3. Rotation Transformation
We can express the rotation transformation described in earlier sections in matrix form as follows:
The rotation matrix in a homogeneous coordinate system is shown below:
4.4. Shearing Transformation
We can express the shearing transformation described in earlier sections in matrix form as follows:
The shearing matrix in a homogeneous coordinate system is shown below:
5. Homogeneous Matrix Composition
Translations become linear when using transformation matrices with homogeneous coordinates, making it possible to combine them easily with all other kinds of transformations:
Since these are homogeneous transformations, The combined transformations can be written as follows:
6. Euler Angles From a Rotation Matrix
We begin by defining rotations about the three principal axes, following a customary practice. Three distinct rotations along the three spatial dimensions can be thought of as a three-dimensional rotation.
6.1. Multi-Axis Rotation Matrices
As an example, consider a rotation of radians about the -axis. Euler’s homogeneous rotation matrix for radians about axis:
Similar to this, we can define rotation of radians about the -axis. Euler’s homogeneous rotation matrix for radians about axis:
Similarly, the definition of a rotation of radians about the -axis is defined. Euler’s homogeneous rotation matrix for radians about axis:
6.2. Generalized Rotation Matrices
A general rotation matrix (Euler’s Generalized Homogeneous Rotation Matrix) can have the following form:
We can think of this matrix as a series of three rotations, one around each main axis. The output will vary depending on the order of the rotation axes, as matrix multiplication does not commute. We’ll rotate the -axis first, followed by the -axis, and then the -axis.
We can use the matrix product to depict such a series of rotations:
6.3. Euler Angles From a Rotation Matrix
By equating each member of a rotation matrix R with its corresponding element in the matrix product , we may get the Euler angles, , , and . We generate nine equations as a result, which we can use to calculate the Euler angles.
The following is the pseudocode for calculating Euler angles from a rotation matrix (2aT: 2-Argument-Arctangent):
7. Euler Angle in Image Rotation
Now that we have the pseudocode and the previously discussed ideas, we can determine the rotational angle of a picture from its rotation matrix.
7.1. The Special Case of Image Rotation
Considering that the image’s location is an – plane, Any image rotation involves a rotation along the -axis. The definition of a rotation of radians about the -axis is as previously stated. Euler’s homogeneous rotation matrix for radians about axis:
We’ll now use (in radians) in place of . The rotation matrix is as follows for an image rotated by an angle :
For the sake of simplicity, we’ve assumed that the two-dimensional image rotates inside its plane. i.e., the rotation of the image occurs in the image plane rather than in three dimensions. For a more general instance, the picture rotation can be thought of as three distinct rotations using the Euler angles mentioned above.
7.2. Euler Angles From an Image Rotation Matrix
The idea is to use the pseudocode for calculating Euler angles from a rotation matrix given above.
We’ll replace with , and will use radians for and in our calculations.
For a given rotation matrix, we’ll solve for using the pseudocode for calculating Euler angles.
7.3. Direct Method for Angle of Image Rotation
The idea here is to first bring the given rotation matrix in the standard format:
Now the angle can be calculated using the following relations:
7.4. More Than One Solution
The fact that more than one rotational sequence around the three main axes might produce the same orientation of an object is an intriguing observation. Thus, we can achieve the desired rotation in a variety of ways.
In this article, we learned how to determine the rotational angle of a given rotation matrix. First, we discussed what image transformations are and how transformation matrices are used to transform the pixels in an image. We were able to estimate the rotation’s angle by examining the rotation matrix’s parts after figuring out its template formula.