Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

The linear algebra prerequisites for template matching, feature comparison, and everything that follows in CV and ML. Every concept is grounded in a concrete imaging problem: if you understand this series, you understand why OpenCV’s TM_CCOEFF_NORMED works the way it does — and by extension, the math underlying every “compare two patches” operation in CV and ML.

Master objective: build up vectors → dot products → norms → cosine similarity → orthogonality → projections → linear transforms, with each step motivated by a concrete imaging scenario.

Parts

File pairTopic
part1_vectors_and_dot_productPixels as vectors; dot product definition and geometric meaning.
part2_norms_and_similarityL2 norm, unit vectors, cosine similarity, and the brightness-offset blind spot.
part3_orthogonality_and_projectionOrthogonality; mean subtraction as orthogonal projection; signal decomposition.
part4_linear_transformsLighting model I=aT+bI = aT + b; orthogonal transforms; DFT; Parseval’s theorem.
exercisesThree practice exercises tying it all together.

Running

Every .py file is standalone:

# from project root
source .venv/bin/activate
python math/linear_algebra/part1_vectors_and_dot_product.py
python math/linear_algebra/part2_norms_and_similarity.py
python math/linear_algebra/part3_orthogonality_and_projection.py
python math/linear_algebra/part4_linear_transforms.py
python math/linear_algebra/exercises.py

Concept map

Image patch
  └── flatten → n-dimensional vector
        ├── L2 norm              → energy / brightness
        ├── unit vector          → pattern (brightness removed)
        ├── dot product          → pixel-by-pixel agreement
        └── cosine similarity    → angle between patterns
              ├── handles contrast scaling ✓
              └── fails on brightness offset ✗
                    └── fix: mean subtraction
                          = orthogonal projection onto [1,1,...,1]
                          = brightness component removed
                          = pattern component preserved

Prerequisites