Class Affine<T>
- Namespace
- AiDotNet.Augmentation.Image
- Assembly
- AiDotNet.dll
Applies random affine transformations (rotation, scale, shear, translation) to an image.
public class Affine<T> : SpatialAugmentationBase<T, ImageTensor<T>>, ISpatialAugmentation<T, ImageTensor<T>>, IAugmentation<T, ImageTensor<T>>
Type Parameters
TThe numeric type for calculations.
- Inheritance
-
AugmentationBase<T, ImageTensor<T>>Affine<T>
- Implements
-
ISpatialAugmentation<T, ImageTensor<T>>IAugmentation<T, ImageTensor<T>>
- Inherited Members
Remarks
Affine transformation is a general geometric transformation that preserves lines and parallelism. It combines rotation, scaling, shearing, and translation in a single operation, providing a powerful way to augment images with realistic geometric variations.
For Beginners: Think of this as combining multiple geometric operations into one. The image can be rotated, stretched, tilted (sheared), and moved around - all at once. This creates more diverse training examples than applying each transformation separately.
When to use:
- General image classification with geometric invariance
- Object detection where objects may be viewed from different angles
- When you need combined geometric variations efficiently
Constructors
Affine((double Min, double Max)?, (double Min, double Max)?, (double Min, double Max)?, (double X, double Y)?, double, InterpolationMode, BorderMode, T?)
Creates a new affine transformation augmentation.
public Affine((double Min, double Max)? rotationRange = null, (double Min, double Max)? scaleRange = null, (double Min, double Max)? shearRange = null, (double X, double Y)? translationRange = null, double probability = 0.5, InterpolationMode interpolation = InterpolationMode.Bilinear, BorderMode borderMode = BorderMode.Reflect, T? borderValue = default)
Parameters
rotationRange(double Pitch, double Confidence)?The range of rotation angles in degrees (min, max). Industry standard default is (-15, 15).
scaleRange(double Pitch, double Confidence)?The range of scale factors (min, max). Industry standard default is (0.9, 1.1).
shearRange(double Pitch, double Confidence)?The range of shear angles in degrees (min, max). Industry standard default is (-10, 10).
translationRange(double Pitch, double Confidence)?The range of translation as fraction of image dimensions (x, y). Industry standard default is (0.1, 0.1) meaning up to 10% in each direction.
probabilitydoubleThe probability of applying this augmentation (0.0 to 1.0). Industry standard default is 0.5.
interpolationInterpolationModeThe interpolation mode for sampling pixels. Industry standard default is Bilinear.
borderModeBorderModeHow to fill pixels that fall outside the original image bounds. Industry standard default is Reflect.
borderValueTThe constant value to use when borderMode is Constant.
Properties
BorderMode
Gets the border mode when pixels fall outside the original image bounds.
public BorderMode BorderMode { get; }
Property Value
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
RotationRange
Gets the rotation angle range in degrees.
public (double Min, double Max) RotationRange { get; }
Property Value
ScaleRange
Gets the scale factor range.
public (double Min, double Max) ScaleRange { get; }
Property Value
ShearRange
Gets the shear angle range in degrees.
public (double Min, double Max) ShearRange { get; }
Property Value
TranslationRange
Gets the translation range as a fraction of image dimensions.
public (double X, double Y) TranslationRange { get; }
Property Value
Methods
ApplyWithTransformParams(ImageTensor<T>, AugmentationContext<T>)
Applies the affine transformation and returns transform parameters.
protected override (ImageTensor<T> data, IDictionary<string, object> parameters) ApplyWithTransformParams(ImageTensor<T> data, AugmentationContext<T> context)
Parameters
dataImageTensor<T>contextAugmentationContext<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 affine transformation.
protected override BoundingBox<T> TransformBoundingBox(BoundingBox<T> box, IDictionary<string, object> transformParams, AugmentationContext<T> context)
Parameters
boxBoundingBox<T>transformParamsIDictionary<string, object>contextAugmentationContext<T>
Returns
- BoundingBox<T>
TransformKeypoint(Keypoint<T>, IDictionary<string, object>, AugmentationContext<T>)
Transforms a keypoint after affine transformation.
protected override Keypoint<T> TransformKeypoint(Keypoint<T> keypoint, IDictionary<string, object> transformParams, AugmentationContext<T> context)
Parameters
keypointKeypoint<T>transformParamsIDictionary<string, object>contextAugmentationContext<T>
Returns
- Keypoint<T>
TransformMask(SegmentationMask<T>, IDictionary<string, object>, AugmentationContext<T>)
Transforms a segmentation mask after affine transformation.
protected override SegmentationMask<T> TransformMask(SegmentationMask<T> mask, IDictionary<string, object> transformParams, AugmentationContext<T> context)
Parameters
maskSegmentationMask<T>transformParamsIDictionary<string, object>contextAugmentationContext<T>