Lulumoy Studio

Math guide

Rotate

Rotates the image by an angle θ around its centre. Positive angles rotate counter-clockwise as the image is seen on screen (with the y axis pointing down).

[x′y′]=[cosθsinθ(1−cosθ)cx−sinθcy−sinθcosθsinθcx+(1−cosθ)cy][xy1]
OpenCV rotation matrix (getRotationMatrix2D), with centre (cx, cy) = (W/2, H/2).
W′=⌈|Wcosθ|+|Hsinθ|⌉,H′=⌈|Wsinθ|+|Hcosθ|⌉
Canvas size when it is expanded to fit the whole image; the translation is adjusted so the image stays centred.

Each output pixel is computed with the inverse transform and interpolated (bilinear); areas outside the original image are black. Rotations of 90°, 180° and 270° with an expanded canvas are done by reordering pixels, with no interpolation or loss.

Parameters

ParameterMeaning
Angle (degrees, counter-clockwise)θ in degrees, between −360 and 360.
Expand canvas to fit the whole imageIf checked, the canvas grows to W′×H′ so no corner is cut; otherwise it keeps W×H.

See also: Interpolation and borders

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. Szeliski. Computer Vision: Algorithms and Applications, 2nd ed. Springer, 2022. szeliski.org/Book/
  3. R. C. Gonzalez, R. E. Woods. Digital Image Processing, 4th ed. Pearson, 2018.