Chapter 3: Affine Transform
An affine transformation is a mathematical operation that maps one set of points to another set of points while preserving collinearity (i.e., straight lines remain straight). It includes translation, rotation, scaling, and shearing as its fundamental components. In deep learning and computer vision, affine transformations are widely used for tasks like image transformation and geometric data augmentation.
Mathematical Notation:
An affine transformation can be represented mathematically as follows:
$$
\mathbf{y} = \mathbf{Ax} + \mathbf{b}
$$
Where:
Examples:
Let’s consider an example of a 2D affine transformation to illustrate the concept. Suppose we want to apply a scaling transformation followed by a translation:
Python (NumPy) Code:
You can implement the affine transformation using NumPy in Python. First, ensure you have NumPy installed:
import numpy as np
# Define the original point
x = np.array([2, 3])
# Define the transformation matrix A
A = np.array([[2, 0],
[0, 3]])
# Define the translation vector b
b = np.array([1, -2])
# Apply the affine transformation
y = np.dot(A, x) + b
print("Original Point (x):", x)
print("Transformed Point (y):", y)This code will output the transformed point after applying the specified scaling and translation.
Affine transformations are fundamental in deep learning when dealing with image data augmentation and spatial transformations. They allow you to modify images and data while maintaining important geometric relationships.