Lulumoy Studio

Math guide

Affine transform (3 points)

A linear map plus a translation. It preserves straight lines, parallelism and ratios along a line, but not angles or distances. Translation, rotation, scaling and shear are particular cases.

[x′y′]=[a11a12a21a22][xy]+[t1t2]
Six unknowns. Each point pair (xk, yk) → (x′k, y′k) gives two linear equations, so three pairs determine the transform (cv::getAffineTransform solves the 6×6 system).
(x2−x1)(y3−y1)−(x3−x1)(y2−y1)≠0
The system has a unique solution if the three points are not collinear (non-zero triangle area). The program requires at least 0.5 px² of area at source and destination.
I′(x′,y′)=I(A−1([x′y′]−t))
cv::warpAffine walks the destination image and looks up each pixel in the source with the inverse transform; since it falls between pixels, it is interpolated.

Points are chosen with the mouse: for each pair, first the source (yellow) and then the destination (cyan). The result keeps the image size.

Parameters

ParameterMeaning
InterpolationHow values at non-integer positions are computed.
Empty areasValue of pixels that fall outside the original image.

See also: Interpolation and borders, Perspective transform (4 points)

References

  1. OpenCV 4.x documentation — Geometric Image Transformations (warpAffine, warpPerspective, getAffineTransform, getPerspectiveTransform, getRotationMatrix2D, interpolation flags). docs.opencv.org/4.x/da/d54/group__imgproc__transform.html
  2. R. Hartley, A. Zisserman. Multiple View Geometry in Computer Vision, 2nd ed. Cambridge University Press, 2004.
  3. R. Szeliski. Computer Vision: Algorithms and Applications, 2nd ed. Springer, 2022. szeliski.org/Book/