Visual walkthrough — Data augmentation for images
Rotating an image is the single most common geometric augmentation in data augmentation — a slightly tilted dog is still a dog. To spin a picture we must move every pixel to a new spot, and the parent note handed you a finished formula (a grid of sines and cosines wrapped in some shifts) that does exactly that.
On this page we throw that finished formula away for now and build it from absolute zero, using pictures. We will not write down a single symbol until we have earned it. By the last step we will have reconstructed the parent's formula piece by piece, and every symbol in it — including the ones the parent used without explaining — will make sense.
We build it in 7 steps. Every step tells you WHAT we just did, WHY we did it, and WHAT IT LOOKS LIKE in its own figure. (Every symbol in this page — , , , , , , , , — is introduced before it is used, right where the picture needs it.)
Step 1 — A pixel is just a point with two numbers
WHAT. Before we can rotate anything, we agree on how to name a location in the image. We pick a corner as the origin (the point "zero"), draw an axis going right (call it ) and an axis going up (call it ). A pixel is then just a pair of numbers : how far right, how far up.
WHY. You cannot move a point until you can say where it is. The pair is that address. Everything on this page is about turning one address into another.
PICTURE. The red dot below lives at . The two dashed lines are literally the two numbers: how far along the -axis, how far up the -axis.

Step 2 — The same point, described by a distance and an angle
WHAT. We describe the same red dot a second way: not by "right and up", but by how far it is from the origin (call that distance ) and what angle its line makes with the -axis (call that angle , the Greek letter "phi").
WHY. Rotation is all about angle. If we keep describing points by and , the angle is hidden. By naming the angle explicitly, rotation becomes the almost-trivial act of changing that one number. This is the whole trick — choose the description in which your operation is easy.
PICTURE. Same dot, new labels: the arrow length is , the little wedge at the origin is .

Step 3 — The bridge between the two descriptions (why sine and cosine appear at all)
WHAT. We connect to . Drop a vertical line from the dot to the -axis. That makes a right triangle: the arrow is the slanted side (hypotenuse), the horizontal piece is , the vertical piece is .
WHY these tools — cosine and sine. We need the horizontal and vertical pieces of a slanted arrow. That is precisely the question cosine and sine were invented to answer:
- = (adjacent side) ÷ (hypotenuse) = "what fraction of the arrow points sideways".
- = (opposite side) ÷ (hypotenuse) = "what fraction of the arrow points up".
No other tool splits a length-at-an-angle into its across and up parts. So they are forced on us.
PICTURE. The triangle, with the ratios labelled right on the sides.

Multiplying each ratio by gives the two pieces back:
Step 4 — Rotate = add to the angle (the actual spin)
WHAT. To rotate the point by (Greek "theta", the amount we spin, e.g. ), we keep the same and change the angle from to . The dot swings along a circle of radius to a new spot, which we name (read "x-prime, y-prime"). The little prime mark just means "the new version of": is where the old landed, is where the old landed.
WHY. Spinning does not change how far a point is from the centre — it only changes its direction. In our chosen description that is literally " stays, grows by ". This is why Step 2 was worth the trouble.
PICTURE. The old dot, the circle it rides on, and the new dot after adding the wedge .

So the new point, described the same triangle-way as Step 3, is:
Each symbol: = unchanged distance, = the point's original angle, = how much we spun, = the new angle, = the new address.
Step 5 — Unpack the "angle plus angle" (why the matrix numbers appear)
WHAT. The expressions have inside them, but we want the answer in terms of the old and , not the hidden . We use the angle-addition identities — standard rules for splitting the cosine and sine of a sum:
WHY this tool. These identities are the only clean way to turn "cosine of a sum" into things we already know (, ). And we know those: from Step 3, and . So after substituting we get rid of , entirely and land purely in old coordinates.
PICTURE. A geometric read of the addition identity — the new horizontal piece is the old across-piece shrunk by minus the old up-piece leaking sideways by .

Multiply each identity by and substitute , :
We never had to measure — it cancelled. That is the payoff of the whole detour.
Stacked as a grid, these two lines are the matrix:
The top row builds , the bottom row builds . The matrix is just a tidy box holding the four numbers we just derived — nothing new is being claimed.
Step 6 — Rotate about the centre, not the corner (the shifts)
WHAT. The rule above spins around the origin (the corner). But an image should spin around its middle, whose address we now name — is the horizontal position of the centre, its vertical position. Otherwise the picture flings itself off-screen. Fix: (1) slide everything so the centre sits at the origin — subtract ; (2) rotate with the Step-5 rule; (3) slide back — add .
WHY. Rotation only knows how to spin about the origin. So we move the point of interest to the origin, do the one thing rotation can do, and undo the move. This "shift → do → unshift" pattern is everywhere in graphics.
PICTURE. Three panels: recentre, spin, put back.

Putting the three moves together gives the full formula — now every symbol in it has been earned:
- ::: coordinates measured from the centre (Step 1 of the fix).
- the matrix ::: the spin we derived in Step 5.
- ::: sliding the whole thing back home.
- ::: the final new address of the pixel.
This is exactly the formula the parent note stated up front — we have now rebuilt it from scratch.
Step 7 — All the edge cases (never surprise the reader)
WHAT. We check the corners no one warns you about. (Reminder from Step 2: whenever we write a degree value like , the and are evaluated on its radian equivalent, e.g. rad.)
WHY. A safe augmentation must behave for every input, including the weird ones: no spin, backward spin, a full loop, and pixels that fall off the frame.
PICTURE. Four mini-cases on one canvas.

- (no rotation). , , so the matrix becomes and . Nothing moves — good, "rotate by nothing" must be harmless.
- Negative (clockwise). but , which just flips the two off-diagonal signs. The picture spins the other way. Both directions are valid augmentations.
- (full loop, i.e. rad). , — back to the identity, image unchanged. Angles wrap around, so and do the same thing.
- Corner pixels leaving the frame. After rotating a rectangle, its corners poke outside the original box, and empty triangles appear inside. Real augmentation libraries fill those empty pixels (with black, reflection, or edge-repeat) and crop the overflow. This is why the parent note warns that large rotations "may move objects partially out of frame" — you are seeing why here.
The one-picture summary

Read it left to right: a pixel is an address → describe it by distance and angle → rotation just adds to the angle → unpack with the addition identity → cancels, leaving the sine/cosine matrix → sandwich it between "shift to centre " and "shift back". The result keeps the label intact, so it is a valid data augmentation.
Recall Feynman retelling — say it like a story
I have a picture and I want to tilt it a bit, because a tilted cat is still a cat and my network should know that. To tilt it I have to send every pixel to a new spot. A pixel is just "so far right, so far up". The trouble is that "right and up" hides the angle, and tilting is all about angle. So I re-describe each pixel by how far it is from the middle and which direction it points. Now tilting is the easiest thing in the world: keep the distance, add my tilt amount to the direction. To translate that back into plain right-and-up coordinates I use the rule for the cosine of two angles added together — and when I plug in what "right" and "up" already were, the hidden angle cancels itself out, leaving a neat little grid of sines and cosines. Finally, because I want to spin around the picture's middle and not its corner, I slide the middle to zero first, spin, and slide back. Check the boring cases — zero tilt does nothing, a full loop does nothing, negative tilts spin the other way, and stray corners get filled or cropped — and I'm done. That grid of sines and cosines is exactly the rotation matrix the parent note handed me. (And remember: the machine wants radians, not degrees.)
Recall Quick self-test
Why do sine and cosine appear at all? ::: They are the only tools that split a slanted arrow of length into its horizontal () and vertical () pieces. What does rotation do to and ? ::: Leaves unchanged; increases by the spin angle . What do and stand for? ::: The horizontal and vertical position of the image centre we rotate about. Why subtract and re-add ? ::: Rotation only spins about the origin, so we shift the centre to the origin, spin, and shift back. What happens at ? ::: The matrix becomes the identity and every pixel stays put. Degrees or radians in code? ::: Radians — convert with .
See also: 3.4.8-Dropout-in-neural-networks and 5.2.3-Overfitting-vs-underfitting for other ways to fight memorization; 6.14-Generalization-in-ML for why invariance helps at test time; 3.4.12-Transfer-learning-CNs for combining augmentation with pretrained features.