Skip to main content
This guide covers essential geometric transformations including resizing, rotation, flipping, cropping, and more advanced affine and perspective transformations.

Overview

Image transformations allow you to modify the geometry of images. Common operations include:
  • Resizing images to different dimensions
  • Rotating images by any angle
  • Flipping images horizontally or vertically
  • Cropping regions of interest
  • Applying affine and perspective transformations

Resizing Images

Resize images to specific dimensions or by a scaling factor.

Interpolation Methods

Rotating Images

Rotate images by 90-degree increments or arbitrary angles.

Simple 90-Degree Rotations

Arbitrary Angle Rotation

When rotating by arbitrary angles, parts of the image may be cropped. To preserve the entire rotated image, calculate new dimensions and adjust the rotation matrix accordingly.

Flipping Images

Flip images horizontally, vertically, or both.

Cropping Images

Crop a region of interest from an image using array slicing.

Affine Transformations

Affine transformations preserve parallel lines and include translation, rotation, scaling, and shearing.

Perspective Transformations

Perspective transformations correct for camera angle and viewpoint changes.
Perspective transformations are commonly used for document scanning, where you select the four corners of a document in a photo and transform it to a flat, rectangular view.

Key Functions

When applying transformations, pixels that fall outside the destination image are cropped. Use appropriate border modes or adjust output dimensions to preserve all data.