Matrix Transformation

# Affine Transformation §

An affine transformation is a linear function with an offset, i.e.

Also called an orthogonal projection.

ChatGPT taught me this, while I was trying to understand how to turn an image from pixel space to meter space, when I was working on F1TENTH for the map converter.

Also saw this at work at Enlighted.

### Matrix Form §

The matrix form of the affine transformation is as follows:

\begin{equation} \mathbf{T}_A = \left[ {\begin{array}{*{20}{c}} \mathbf{A} & \mathbf{t}\\ {{\mathbf{0}^T}} & 1 \end{array}} \right] \end{equation}

Unlike the Euclidean Transformation, the affine transformation requires only to be an invertible matrix, not necessarily an orthogonal matrix. After the affine transformation, the cube is no longer square, but the faces are still parallelograms.

In Eigen

Eigen::Affine3d T;

Affine transformation combines linear transformations with a translation component. There are

### ChatGPT §

Affine transformation is a linear mapping method that preserves points, straight lines, and planes. Sets of parallel lines remain parallel after an affine transformation. The affine transformation technique is typically used to correct for geometric distortions or deformations that occur with non-ideal camera angles.

import numpy as np
from scipy.ndimage import affine_transform

# Create a sample image array
image = np.zeros((100, 100))
image[50, 50] = 1

# Define the transformation matrix
origin = [10, 20]  # new origin coordinates
scale = [2, 3]  # new scale factors
matrix = np.array([[scale, 0, origin],
[0, scale, origin],
[0, 0, 1]])

# Apply the transformation
transformed_image = affine_transform(image, matrix)

# Display the original and transformed images
import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4))
ax1.imshow(image)
ax1.set_title("Original")
ax2.imshow(transformed_image)
ax2.set_title("Transformed")
plt.show()