72 min total

Computer Vision & OpenCV

Linear algebra primer

Linear algebra primer

Notes on computer vision, from image representation, filtering, and local features to neural networks, generative models, attention, and multimodal learning. The final pages cover OpenCV image dimensions and a notebook sketch.

A column vector has n rows and one column:

Its transpose is a row vector:

Uses of Vectors

  • Represents offsets in 2D/3D space, vector point is just a vector from origin
  • Pixel, gradients can be stored as vectors to compute distance calculations

Square matrix: n x n dimensions

Grayscale images are stored as an mxn matrix where each entry represents pixel brightness.

Upper left corner in these matrices is [y, x] = [0, 0]

Color images are stored as mxnx3 matrix (RGB)

Three color channels form an image tensor

Norm

A norm measures vector magnitude and obeys the following properties.

Norm properties:

  • Non negativity: for all
  • Definiteness:
  • Homogeneity: for any scalar t
  • Triangle inequality: for all x, y

Vector Norms

L2 Norm (Euclidean Norm)

L1 Norm (Manhattan Norm)

Lp Norm (Generalized Norm)

L-infinity Norm (Maximum Norm)

Vector operations

Inner product (Dot Product)

A row vector multiplied by a column vector produces one scalar.

If B is a unit vector, A⋅B gives the projection of A in the direction of B, A⋅B tells you how much of vector A points in the direction of B, when B has length 1.

Projection of one vector onto another

Matrix Operations

Matrix multiplication

If A: m×n, B: n×p, then C=A.B: m×p

Each output entry is the dot product of a row of A with a column of B.

Addition

Scaling

Matrix Transpose

Trace

Trace(A) = sum of diagonal elements

Trace properties

Determinant

Determinant properties

A square matrix is singular exactly when its determinant is zero.

Matrix properties

  • Associative: (AB)C = A(BC)
  • Distributive: A(B+C) = AB+AC
  • Not Commutative: ABBA
  • Powers: only for square matrices
  • Identity matrix:
  • Diagonal matrix:

All off-diagonal entries of a diagonal matrix are zero.

  • Symmetric matrix:
  • Skew-symmetric matrix:

Matrix Norms

Frobenius norm

Matrix inverse

Inverse properties

If inverse exists,

If inverse doesn’t exists,

Matrix Rank

col-rank(A) - Maximum number of linearly independent column vectors in A row-rank(A) - Maximum number of linearly independent row vectors in A

Linear Independence

Vectors are linearly independent when no vector can be written as a linear combination of the others; equivalently, only the all-zero coefficients give a zero linear combination. Independence does not require perpendicular vectors.

Rank Properties

  • col-rank(A)row-rank(A)rank(A)
  • If rank(A)=1 → transformations map points onto a line

This singular transformation maps every point onto the line y = 2x.

  • Full rank is when mm matrix's rank is m. It maps m1 vector uniquely into another m1 vector, this matrix's inverse exists
  • if rank < m then det(A)=0, atleast one dimension collapses, this matrix's inverse do not exist

Matrix Transformations

scaling

The left 2×2 array is the scaling matrix; [x,y]ᵀ is the input vector, and [sₓx,sᵧy]ᵀ is the scaled vector.

Rotation

The vector [x,y]ᵀ is the input, the middle 2×2 matrix rotates it by θ, and [x′,y′]ᵀ is the output.

Det(R) = 1

Multi-transformation

Point p is scaled by S, Then rotated By , then rotated by matrix. We can precompute then transform points to reduce computation

Matrix translations

A 2×2 linear transform cannot express translation. Homogeneous coordinates add a constant coordinate so translation becomes a matrix operation.

Notation note: the original translation coordinates c and f are written as tₓ and tᵧ here; they represent the same horizontal and vertical offsets.

Composing scaling and translation

For column vectors, transformations apply from right to left: TRS scales, then rotates, then translates. Changing the order generally changes the result.

Why the order of transformations matters

In TRS, translation is applied last. In RST, the translation vector is itself scaled and rotated. The two outputs generally differ.

⚠Note: T.S.P != S.T.P