Table of Contents

Class Rotation<T>

Namespace
AiDotNet.Augmentation.Image
Assembly
AiDotNet.dll

Rotates an image by a random angle within a specified range.

public class Rotation<T> : SpatialAugmentationBase<T, ImageTensor<T>>, ISpatialAugmentation<T, ImageTensor<T>>, IAugmentation<T, ImageTensor<T>>

Type Parameters

T

The numeric type for calculations.

Inheritance
Rotation<T>
Implements
Inherited Members

Remarks

Rotation randomly rotates the image around its center point by an angle sampled from the specified range. This simulates viewing objects from slightly different angles, which helps the model become robust to orientation variations.

For Beginners: Imagine tilting your camera slightly when taking a photo. The same object photographed at a slight angle is still the same object. This augmentation teaches your model to recognize objects even when they're not perfectly aligned.

When to use:

  • Object classification where objects might appear at different angles
  • Document analysis (scanned documents may be slightly tilted)
  • Medical imaging where acquisition angle varies
  • Satellite imagery where orientation is arbitrary

When NOT to use:

  • Facial recognition (faces should be upright)
  • Handwriting recognition (letters need consistent orientation)
  • Tasks where specific orientation is part of the classification

Constructors

Rotation(double, double, double, BorderMode, T?, InterpolationMode)

Creates a new rotation augmentation.

public Rotation(double minAngle = -15, double maxAngle = 15, double probability = 0.5, BorderMode borderMode = BorderMode.Reflect, T? borderValue = default, InterpolationMode interpolation = InterpolationMode.Bilinear)

Parameters

minAngle double

The minimum rotation angle in degrees. Use negative values for counter-clockwise rotation. Industry standard default is -15 degrees.

maxAngle double

The maximum rotation angle in degrees. Industry standard default is 15 degrees.

probability double

The probability of applying this augmentation (0.0 to 1.0). Industry standard default is 0.5.

borderMode BorderMode

How to fill pixels that fall outside the original image bounds. Industry standard default is Reflect (mirror pixels at the edge).

borderValue T

The constant value to use when borderMode is Constant.

interpolation InterpolationMode

The interpolation mode for sampling pixels. Industry standard default is Bilinear for smooth results.

Remarks

For Beginners: The angle range controls how much rotation is applied. A range of -15 to +15 degrees creates subtle rotations that look natural. Larger ranges (like -45 to +45) create more dramatic rotations.

Properties

BorderMode

Gets the border fill mode when pixels fall outside the original image bounds.

public BorderMode BorderMode { get; }

Property Value

BorderMode

BorderValue

Gets the constant value used when BorderMode is Constant.

public T BorderValue { get; }

Property Value

T

Interpolation

Gets the interpolation mode for pixel sampling.

public InterpolationMode Interpolation { get; }

Property Value

InterpolationMode

MaxAngle

Gets the maximum rotation angle in degrees.

public double MaxAngle { get; }

Property Value

double

MinAngle

Gets the minimum rotation angle in degrees (can be negative for counter-clockwise).

public double MinAngle { get; }

Property Value

double

Methods

ApplyWithTransformParams(ImageTensor<T>, AugmentationContext<T>)

Applies the rotation transformation and returns transform parameters.

protected override (ImageTensor<T> data, IDictionary<string, object> parameters) ApplyWithTransformParams(ImageTensor<T> data, AugmentationContext<T> context)

Parameters

data ImageTensor<T>
context AugmentationContext<T>

Returns

(ImageTensor<T> data, IDictionary<string, object> parameters)

GetParameters()

Gets the parameters of this augmentation.

public override IDictionary<string, object> GetParameters()

Returns

IDictionary<string, object>

A dictionary of parameter names to values.

TransformBoundingBox(BoundingBox<T>, IDictionary<string, object>, AugmentationContext<T>)

Transforms a bounding box after rotation.

protected override BoundingBox<T> TransformBoundingBox(BoundingBox<T> box, IDictionary<string, object> transformParams, AugmentationContext<T> context)

Parameters

box BoundingBox<T>
transformParams IDictionary<string, object>
context AugmentationContext<T>

Returns

BoundingBox<T>

TransformKeypoint(Keypoint<T>, IDictionary<string, object>, AugmentationContext<T>)

Transforms a keypoint after rotation.

protected override Keypoint<T> TransformKeypoint(Keypoint<T> keypoint, IDictionary<string, object> transformParams, AugmentationContext<T> context)

Parameters

keypoint Keypoint<T>
transformParams IDictionary<string, object>
context AugmentationContext<T>

Returns

Keypoint<T>

TransformMask(SegmentationMask<T>, IDictionary<string, object>, AugmentationContext<T>)

Transforms a segmentation mask after rotation.

protected override SegmentationMask<T> TransformMask(SegmentationMask<T> mask, IDictionary<string, object> transformParams, AugmentationContext<T> context)

Parameters

mask SegmentationMask<T>
transformParams IDictionary<string, object>
context AugmentationContext<T>

Returns

SegmentationMask<T>

Remarks

Uses the same rotation center as the image transformation, scaled to mask dimensions if they differ from image dimensions, to ensure proper alignment.