← Image Processing for EveryoneToolsInVisionLearning Center
Geometry and Alignment · Lesson 50

Rotate and Warp with an Affine Transform

A rotated product image no longer aligns with its inspection mask.

Read the full lesson and open its transcript below. A narrated video will be added after production.

Lesson overview

What you will learn

A rotated product image no longer aligns with its inspection mask.

  1. A practical question
  2. The useful idea
  3. Work through the example
  4. Limits and next step
01

A practical question

The product rotates on the conveyor, and its old rectangular mask no longer follows it. Rotating only the photograph would be a mistake. The mask and every annotation point need the same geometric mapping.

02

The useful idea

An affine transform combines a linear change with a translation. It can rotate, scale, shear, and move an image. Straight lines remain straight and parallel lines remain parallel, although angles and lengths may change. That preservation tells us when an affine model is plausible and when a perspective view may require something else.

03

Work through the example

Take the four corners of a box around the product and transform each one. A rotated rectangle usually becomes a quadrilateral in the new coordinates. If the annotation format only accepts axis-aligned boxes, enclose the transformed corners in a new box and check the extra background it includes. Overlap the new mask with the warped image rather than trusting coordinates alone. Rotate a photographed package and keep a rectangle around it. Transforming only the rectangle center is insufficient: its corners move, and its new axis-aligned bounding box may grow. Apply the same mapping to each corner, then redraw the annotation from their new positions. If the camera also introduces perspective, a single affine transform may be the wrong model. Compare the transformed edges with visible package edges before treating the overlay as ground truth. Use this case to test your understanding: Rotate a rectangle and transform each corner to update its annotation. Here is the limitation to watch for: A single affine mapping cannot model arbitrary perspective changes. This supports a careful conclusion: An affine transform combines linear operations and translation and preserves straight lines and parallelism.

04

Limits and next step

Write down the transform direction, output size, and coordinate convention. Next, we'll make a separate choice: how to fill the output pixels of a warped image without inventing invalid class labels in its mask.

Worked example

Rotate a rectangle and transform each corner to update its annotation.

Knowledge check

Quick check: test your understanding

Try it yourself: Consider this case: Rotate a rectangle and transform each corner to update its annotation. Explain how you would check the result. In your answer, address this limitation: A single affine mapping cannot model arbitrary perspective changes.

Check the reasoning

An affine transform combines linear operations and translation and preserves straight lines and parallelism. A single affine mapping cannot model arbitrary perspective changes.

What is the main idea behind rotate and warp with an affine transform?

An affine transform combines linear operations and translation and preserves straight lines and parallelism.

How is it used in the example?

Rotate a rectangle and transform each corner to update its annotation.

What limitation should be checked?

A single affine mapping cannot model arbitrary perspective changes.

Further reading

Digital Image Processing, 4th edition — Rafael C. Gonzalez and Richard E. Woods.

Original ToolsInVision teaching examples. Editorial approach · Suggest a correction

Accessible referenceLesson 50 transcript308 words · Narration ready for the upcoming videoOpen transcript

The product rotates on the conveyor, and its old rectangular mask no longer follows it. Rotating only the photograph would be a mistake. The mask and every annotation point need the same geometric mapping.

An affine transform combines a linear change with a translation. It can rotate, scale, shear, and move an image. Straight lines remain straight and parallel lines remain parallel, although angles and lengths may change. That preservation tells us when an affine model is plausible and when a perspective view may require something else.

Take the four corners of a box around the product and transform each one. A rotated rectangle usually becomes a quadrilateral in the new coordinates. If the annotation format only accepts axis-aligned boxes, enclose the transformed corners in a new box and check the extra background it includes. Overlap the new mask with the warped image rather than trusting coordinates alone. Rotate a photographed package and keep a rectangle around it. Transforming only the rectangle center is insufficient: its corners move, and its new axis-aligned bounding box may grow. Apply the same mapping to each corner, then redraw the annotation from their new positions. If the camera also introduces perspective, a single affine transform may be the wrong model. Compare the transformed edges with visible package edges before treating the overlay as ground truth. Use this case to test your understanding: Rotate a rectangle and transform each corner to update its annotation. Here is the limitation to watch for: A single affine mapping cannot model arbitrary perspective changes. This supports a careful conclusion: An affine transform combines linear operations and translation and preserves straight lines and parallelism.

Write down the transform direction, output size, and coordinate convention. Next, we'll make a separate choice: how to fill the output pixels of a warped image without inventing invalid class labels in its mask.